Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20578: Empty update of Activity assignee/target results into DB e… #10361

Merged
merged 2 commits into from
May 18, 2017

Conversation

jitendrapurohit
Copy link
Contributor

@jitendrapurohit jitendrapurohit commented May 15, 2017

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@eileenmcnaughton
Copy link
Contributor

What happens if we just remove that check, like the code comments suggest to do?

@jitendrapurohit
Copy link
Contributor Author

This part is to check if correct contact ids are passed in source, assignee and target keys of params. If there are n no. of contacts in civi and n+1 value is passed to any of these three fields, an Invalid contact id exception is thrown.

If I remove this, the error would be replaced by DB error(constraint violation). Similar error is shown on contribution create api if contact_id is passed to a value not present in civicrm_contact.

@eileenmcnaughton
Copy link
Contributor

I think we decided early on with the api that we didn't really want to impose a performance cost on every api call just to give developers clearer information when they get it wrong.

I don't know if it has been changed - since I can't find evidence of calls to https://github.com/civicrm/civicrm-core/blob/master/api/v3/utils.php#L1639-L1639 but there was code that validated constraints AFTER DB constraint error - giving extra information in that case, but not adding unnecessary queries if all the fields were present

@jitendrapurohit
Copy link
Contributor Author

@eileenmcnaughton Moved foreign key validation for activity contact to wrapper when they are passed as an array. Now the error would be shown as

image

@eileenmcnaughton
Copy link
Contributor

@jitendrapurohit that seems good as an api behaviour, and the test fails are unrelated.

Is the screen capture you displayed a 'real' one or a simulated one' - if the former should we be catching the exception at the display layer?

@jitendrapurohit
Copy link
Contributor Author

jitendrapurohit commented May 18, 2017

This is the simulated one which I got when I write the api in Invoke.php(just to test). The real would be the yellow part with the backtrace of where the api is being called(if backtrace is enabled on the site). When tried from the api explorer, it displays like

image

where the error_message was only DB Error: constraint violation (before the fix in wrapper and removing the api/v3/activity.php sql). Now it contains the msg of invalid contact id passed in params.

@eileenmcnaughton
Copy link
Contributor

Ok - I think that is good. The limited error message is correct & the extra info is good too.
Performance should be slightly improved. Test coverage improved, albeit not overing the failure & code complexity reduced.

Merging

@eileenmcnaughton eileenmcnaughton merged commit f8431f1 into civicrm:master May 18, 2017
@jitendrapurohit jitendrapurohit deleted the CRM-20578 branch May 18, 2017 04:20
@jitendrapurohit
Copy link
Contributor Author

Thanks @eileenmcnaughton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants