Skip to content
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

Fix duplicate merge to not disregard zero values. #12669

Merged
merged 1 commit into from
Dec 20, 2018

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Aug 15, 2018

Overview

Fix merge process to treat 0 as different to NULL

Before

A contact who has selected 0 for a checkbox field is merged to a contact who has a NULL value. The 0 value is not transferred over.

After

A contact who has selected 0 for a checkbox field is merged to a contact who has a NULL value. The 0 value is transferred over.

Technical Details

In a checkbox situation the difference between
0 and null is significant (I chose not to opt in vs
I was never presented with a choice).

I also added a test to check that a conflict between 0 & 1 is treated as a conflict (it turns out it is)

ping @JKingsnorth

@civibot
Copy link

civibot bot commented Aug 15, 2018

(Standard links)

@eileenmcnaughton
Copy link
Contributor Author

@ejegg @mepps

@eileenmcnaughton eileenmcnaughton force-pushed the dedupe_zero branch 3 times, most recently from c1f3e07 to 6fa6791 Compare August 16, 2018 07:42
Copy link
Contributor

@ejegg ejegg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good set of tests! Let's also ignore empty arrays (when I tried to apply similar logic to the non-custom field bit it found a lot of those) and do strict comparison in the in_array test.

// However I can't think of a case where an empty string is more meaningful than null
// or where it would be FALSE or something else nullish.
$valuesToIgnore = [NULL, ''];
if (!in_array($key1, $valuesToIgnore) || !in_array($key2, $valuesToIgnore)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use the 'strict' argument to in_array, and add the empty array to $valuesToIgnore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ejegg good thinking - done. Also port in gerrit

@seamuslee001
Copy link
Contributor

@eileenmcnaughton the test failures i think might be related https://test.civicrm.org/job/CiviCRM-Core-PR/22120/

Currently a field with 0 in it will not be carried across in a merge. In fact in a checkbox situation the differenct between
0 and null is significant (I chose not to opt in vs
I was never presented with a choice).

This patch preserves the 0. I would note that
further digging is required to see how a confict is handled
- ie. if one contact has 0 & the other has 1 is this blocked
as a confligct

Additional test on conflict handling
@eileenmcnaughton
Copy link
Contributor Author

@JKingsnorth @deepak-srivastava any takers for review?

@JKingsnorth
Copy link
Contributor

@eileenmcnaughton I'll review this tomorrow [=

@eileenmcnaughton
Copy link
Contributor Author

thanks @JKingsnorth

@JKingsnorth
Copy link
Contributor

Sorry, something came up, first on my list tomorrow.

@JKingsnorth
Copy link
Contributor

I'm currently unable to recreate the original issue, by doing:

  • I created an optional checkbox with the values Zero - 0 and One - 1
  • I created two contacts, one with 0 and one with 1
  • I batch merged them
  • Conflict detected on batch merge (before patch was applied)

So I've opened a PR with just the tests to investigate further: #12750

@JKingsnorth
Copy link
Contributor

@eileenmcnaughton - weird, the tests you wrote passed without the patch!

So presumably we can keep the code as-is (unless you can dig out the steps to recreate the issue you were experiencing) and just add the tests?

@mattwire
Copy link
Contributor

@eileenmcnaughton What's the status with this one?

@monishdeb
Copy link
Member

@eileenmcnaughton @JKingsnorth @mattwire I have moved and modified the UTs in a separate PR to capture the two use-cases. This is the #13323 which is expected to fail without this patch. Please have a look

@monishdeb
Copy link
Member

I am merging this PR as it fixes the issue. As per the UT concern, I made the desired change in UT (PR #13323) to capture this use-case. After merge I will rebase my PR for merge-on-pass, to show this fix worked for '' and NULL

@monishdeb monishdeb merged commit a48554e into civicrm:master Dec 20, 2018
@eileenmcnaughton eileenmcnaughton deleted the dedupe_zero branch December 20, 2018 04:41
@eileenmcnaughton
Copy link
Contributor Author

Thanks @monishdeb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants