-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
API4: Allow save() to match on null values #24971
API4: Allow save() to match on null values #24971
Conversation
(Standard links)
|
I'm not entirely sure that it was. But I'm not against updating it to do so, with a unit test, and I think we ought to add an additional safety-guard that a positive match must include at least one non-null value. |
@colemanw, the already-merged PR #22882 (@mattwire) intended to allow matching on null -- see the comment. I'm keen on having this work properly. I added a test. I also added in the "safety guard" (this commit) but after thinking about it, I took it back out. I don't know why we'd assume people won't want to match on a set of empty values. The function already aborts if the number of matches > 1, and that seems like enough of a safety guard. |
Wow, that was fast! |
NULL or empty-string only matches NULL or empty-string (using the IS EMPTY operator). And I agree, the test was impressively clever, but almost impossible to read, so I've rewritten it from scratch. |
I could break the test up into a few smaller tests to make it even more grokkable, @colemanw, |
Contact::delete(FALSE) | ||
->setUseTrash(FALSE) | ||
->addWhere('id', 'IN', $allContactIds) | ||
->execute(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was thoughtful of you to add this cleanup at the end, but that's not how we do test cleanup :)
For one thing, it's a pain for test authors to remember to do this every time, and, more importantly, if the test fails then it will never get to this step!
Best practice these days is to use $this->createTestRecord()
instead of the api. As the name implies, the function creates test records... but it also automatically cleans them up afterwards, even if the test crashes halfway through!
@highfalutin test is fine now can you just remove the bit at the end and use |
@highfalutin are you able to update this? It would be great to get it merged. |
@colemanw a busy few weeks here but I'll get to it. IIRC, we can't take out the bit at the end and still have a passing test, but I'll take another look |
8abe3a3
to
fe4bd48
Compare
@colemanw I got rid of the "delete" action, and switched to relying on TransactionalInterface to handle cleanup. Back to using a data provider. But hopefully the test is still not too hard to grok. |
I believe the test failure is unrelated. |
Can one of the admins verify this patch? |
civibot, test this please |
fe4bd48
to
4849b6e
Compare
@colemanw can we get this into the new rc? |
@civicrm-builder retest this please |
Yes, thanks for your work on this @highfalutin |
Before
Code was trying to allow save() to match on null values, but was shooting itself in the foot.
After
Matching on fields works even when their value is null.