-
-
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
Disambiguate Address.state_province_id:abbr
#25550
Conversation
(Standard links)
|
The PHP aspect seems to be easier than the MySQL aspect. I've extracted that as a separate PR (#25552). |
Rebased to build on top of PHP-only PR (25552). Changed the approach on the MySQL fix. (The earlier patch had filled in the Pushed up a simpler approach that doesn't require extra metadata. |
CRM/Core/PseudoConstant.php
Outdated
@@ -1499,7 +1499,8 @@ public static function renderOptionsFromTablePseudoconstant($pseudoconstant, &$p | |||
$select = 'SELECT %1 AS id, %2 AS label'; | |||
$from = 'FROM %3'; | |||
$wheres = []; | |||
$order = 'ORDER BY %2'; | |||
$order = 'ORDER BY %2, id'; | |||
// Example: 'ORDER BY abbreviation, id' because abbreviations are not unique. |
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.
Maybe check that the id is in the fields? Import tables do not have an _id
field -
It looks like you can use some variant of
if (in_array('id', $availableFields), TRUE) {
...
}
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.
@eileenmcnaughton Good idea. Updated.
Also, rebased on top of current master. (Since the related PR was merged, the diff should now look smaller.)
Consider `ContactJoinTest::testCreateWithPrimaryAndBilling` which writes the value: 'address_billing.state_province_id:abbr' => 'AK', The symbol 'AK' can map to three places: Akwa Ibom (Nigeria), Atakora (Benin), and Alaska (USA). This is an ambiguous choice. It should be resolved in a consistent way. One flavor of ambiguity comes from MySQL. When loading abbreviations, Civi queries with `ORDER BY abbreviation`. This is a *typically* stable, but it has no *guaranteed* resolution. Adding a secondary sort key makes the outcome clear/unambiguous.
civibot, test this please |
It looks very small indeed. This seems safe & sensible to me |
Overview
The test
ContactJoinTest::testCreateWithPrimaryAndBilling
is flaky. This stems from following:The symbol 'AK' can resolve to three places: Akwa Ibom (Nigeria), Atakora (Benin), and Alaska (USA). This is an ambiguous choice. It should be resolved in a consistent way.
ping @colemanw
Before
There are two layers of flakiness:
civicrm_state_province
records, it usesORDER BY abbreviation
. This is ambiguous.The PHP flakiness is more apparent than the MySQL flakiness. You can easily switch PHP versions to observe the difference (which is why
testCreateWithPrimaryAndBilling
usually fails onmin
and usually passes onmax
). For MySQL, the problem depends more on internal/arbitrary details, and the test-assertions match the usual behavior -- so failures there are less common.After
Both layers should be consistent:
civicrm_state_province
withORDER BY abbreviation, id
. This is unambiguous.