-
-
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
avoid back trace when importing preferred communication method #21433
avoid back trace when importing preferred communication method #21433
Conversation
(Standard links)
|
d81bbaf
to
c3be6a8
Compare
I think I have the right fix now (the previous commit causing the regression was not properly tested against a multi-select field). And it's locked in with a test. |
c3be6a8
to
65a6482
Compare
Woops - one more commit + squash (I accidentally left in my incorrect earlier fix). |
$this->assertEquals('da_DK', $contact['preferred_language'], "Import preferred language with label."); | ||
|
||
$importer = $processor->getImporterObject(); | ||
$fields = ['Ima', 'Texter', "4,1", "1", "da_DK"]; |
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's interesting that this works in the test, because I can't get numbers to work for this field in the UI, either before or after the patch or using single-value or multi.
Mystery?
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.
Huh - interesting. I put the values into the test because I thought, why not expand the test coverage? But didn't test entering the values in the UI. What happens when you try? Do you get an error?
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.
You can't get past the import screens to see what would happen - it gives you the excel file to download with errors which says it thinks the field has an invalid value.
|
@demeritcowboy - ahhh.... see that now. The test code is executing the same code as the UI, but the code doesn't consider it a fatal error (it's more of an FYI) so the test code happily continues. I think it's good for the test to remain and a new issue could be opened to:
|
Overview
When importing a contact with preferred communication method set, I get:
CiviCRM_API3_Exception: "'' is not a valid option for field preferred_communication_method"
The problem surfaced after upgrading from 5.33 to 5.39.
I traced it back to this code and can fix it with this simple change.
The problem with the original code is that
$formatted[$fieldName]
is anarray with the key set to the chosen value and the value set to 1. So, the array_search always fails since the key it's looking for is an array, not a string.
I think the line:
&& empty($fieldSpec['options'][$formatted[$fieldName]])) {
Is also not quite right but not sure how to change it.
Before
Importing a contact with preferred communication method set results in:
'' is not a valid option for field preferred_communication_method
After
The contact record is imported.
Technical Details
The problem may have been introduced via cdfa664.
Comments
I don't think this fix is quite there yet but would love to get some feedback.
Also, in this particular use case, the label for the SMS option has been changed to "Text message" but I don't think that has an impact on this issue.