-
-
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
Allow API4 match to match an empty value #22882
Conversation
(Standard links)
|
Thanks @mattwire - Jenkins says you have to add spaces around the "<" on line 56 of the test. |
@mattwire your new test didn't pass |
@colemanw This seems to be a setup/teardown issue. When the test is run by itself it passes every time. But when run as a suite (eg. api/v4/Action) it fails suggesting that something external is interfering with the test? |
@mattwire I think the match criteria isn't unique enough, and running the test when there's other data in the database, you get more than one match for a contact with first name "Abc" and a blank external identifier. |
That works. Typically in tests requiring unique names I use something like |
Overview
The new matching functionality on X::save is nice but I found an issue that I find counterintuitive / confusing.
For example if you have some data to import and some has an external_identifier then you might match on first_name,last_name,external_identifier but if external_identifier is empty it won't match because it does external_identifier = '' and that's not the same as external_identifier IS NULL
ie. https://github.com/civicrm/civicrm-core/blob/master/Civi/Api4/Generic/AbstractSaveAction.php#L145
@colemanw said: Maybe patch that line to use the IS EMPTY operator if $val === ''?
Pending test to be added here:
civicrm-core/tests/phpunit/api/v4/Action/SaveTest.php
Line 45 in db11224
Before
Matching on an empty string doesn't match.
Eg. match on: first_name='bob'; external_identifier=''; creates new record even if that exists.
After
Matching on an empty string matches.
Eg. match on: first_name='bob'; external_identifier=''; updates existing record.
Technical Details
This is particularly noticeable when doing imports.
Comments
@colemanw I've added a test now.