-
-
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
dev/core#4231 Fix failure to import non-default state #28557
Conversation
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
The issue associated with the Pull Request can be viewed at https://lab.civicrm.org/dev/core/-/issues/4231 |
test this please |
Hmm, I just spent about half an hour debugging this test and tracing through the import code... I'm finding those classes particularly difficult to follow. Generally speaking, the problem is that each field is being processed atomically, the importer classes are failing to pass relevant context into APIv4.getFields, which APIv4 needs so it can handle the interrelatedness of fields like county->state->country. I don't know how much we'd have to fight against the Importer code to achieve this, but the ideal solution would be to give APIv4 the context data it needs. The general formula for this (as seen in APIv4's own handling of pseudoconstant lookups) is:
|
@colemanw hmm - the importer code builds up an array of available options for each field it is importing at the start. Then while importing it checks the value against the id, name, label & abbreviation to find a match. It doesn't know all the countries it will be dealing with when it starts, or even if all rows that have a state will have a country field. And if they don't have a country it might not be the site default country - (for a small number of states that would be ambigous & would rightly fail on import) In my database there are less than 2k states - that doesn't feel to me like the sort of size that I would want to avoid loading all at once, given each row doesn't have that many keys (I would want to avoid serilizing/unserializing it though) - so I'm really looking for the |
@eileenmcnaughton if you want to fetch all states, there's probably a way to do that. But I think the underlying problem will persist: without passing any context to the api, it has no way of knowing the difference between e.g. Maryland, USA and Maryland, Liberia, as this test demonstrates: civicrm-core/tests/phpunit/api/v3/AddressTest.php Lines 487 to 488 in d2ce7f7
|
@colemanw yeah - but the import class handles that - ie it works with the information it has to get the best pick or lets the user know if it is unresolvably ambigous - but it does that row by row whereas it resolves options at the start |
Also worth noting that import does a validate process before the import process |
@eileenmcnaughton where does the import code fetch the list of states? |
@colemanw it does it here civicrm-core/CRM/Import/Parser.php Lines 1741 to 1745 in 68108b0
|
@eileenmcnaughton I don't think it's specific to APIv4. The API just delegates to civicrm-core/CRM/Core/BAO/Address.php Lines 1221 to 1229 in ab913b2
|
@colemanw hmm - that |
@eileenmcnaughton unfortunately not. And that would also affect how the output is formatted. |
@colemanw OK - I think I'd gotten to that conclusion - I might see if I can lazy load in some way but will think about that |
6cc0aa1
to
185e3df
Compare
185e3df
to
ca69e98
Compare
Ok this is working now so let's merge it. |
Overview
Fixes https://lab.civicrm.org/dev/core/-/issues/4231
Before
As described in https://lab.civicrm.org/dev/core/-/issues/4231 & as replicated in the attached test
After
Fixed
Technical Details
The import is relying on apiv4 getfields to return the available state options here
civicrm-core/CRM/Import/Parser.php
Lines 1741 to 1745 in 68108b0
getFields is returning only the states from the default country, not other countries even though the api call does not specify them.
Note that the default country is not configured by default & perhaps is more commonly used on older sites. Also note that when set it literally is the default country, not the only country
Comments