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

[NFC] Use insert ignore for inserts into civicrm_extension to stop warnings on duplicate entry for sequential credit notes extension #16644

Merged
merged 1 commit into from
Feb 28, 2020

Conversation

seamuslee001
Copy link
Contributor

@seamuslee001 seamuslee001 commented Feb 27, 2020

Overview

This resolved notices such as

/home/jenkins/bknix-dfl/build/core-16642-770zv/web/sites/all/modules/civicrm/Civi/Test.php:205:
bool(false)
/home/jenkins/bknix-dfl/build/core-16642-770zv/web/sites/all/modules/civicrm/Civi/Test.php:206:
array(3) {
  [0] =>
  string(5) "23000"
  [1] =>
  int(1062)
  [2] =>
  string(72) "Duplicate entry 'sequentialcreditnotes' for key 'UI_extension_full_name'"
}

occurring when running tests

Before

Notices show

After

No notices

Technical Details

The issue is that civicrm_extension table is not 'cleaned' out between test runs unlike other tables to ensure that we don't remove information on enabled extensions. This adds in some logic specific to the sequential credit notes extension as it is added via the civicrm_data.mysql file

ping @demeritcowboy @eileenmcnaughton @totten

@civibot
Copy link

civibot bot commented Feb 27, 2020

(Standard links)

@civibot civibot bot added the master label Feb 27, 2020
@eileenmcnaughton
Copy link
Contributor

@seamuslee001 what about truncating the table between runs? We've done things very specific to this extension because it's the first but we don't see it being the only

@eileenmcnaughton
Copy link
Contributor

(presumably we would truncate in tearDown?)

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton the table has been specifically excluded from the truncate https://github.com/civicrm/civicrm-core/blob/master/Civi/Test/Schema.php#L101 this i suspect is designed to help extension testing

@eileenmcnaughton
Copy link
Contributor

Hmm - well I'm OK merging this as it fixes but going forwards we probably need another way to check

@demeritcowboy
Copy link
Contributor

It works for me locally to fix it. I wonder if another way is to use INSERT ON DUPLICATE KEY UPDATE in the civicrm_data xml template, or might that then end up missing failures that should get caught?

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 ohh - I like @demeritcowboy's suggestion

…rnings on duplicate entry for sequential credit notes extension
@seamuslee001 seamuslee001 changed the title [NFC] Remove sequential credit notes extension from test db before be… [NFC] Use insert ignore for inserts into civicrm_extension to stop warnings on duplicate entry for sequential credit notes extension Feb 28, 2020
@seamuslee001
Copy link
Contributor Author

updated it now @eileenmcnaughton @demeritcowboy

@eileenmcnaughton
Copy link
Contributor

Cool- next round we can get more generic

@demeritcowboy
Copy link
Contributor

Insert Ignore is different than Duplicate Update and will silently skip errors on real sites for the initial insert since this file isn't just for tests. I guess as long as it doesn't stay like this permanently?

@seamuslee001
Copy link
Contributor Author

so @demeritcowboy if someone had actually disabled the extension we shouldn't be going through and updating the civicrm_extension row hence an insert ignore

@demeritcowboy
Copy link
Contributor

Ok I'm not following again but if you're good.

@totten
Copy link
Member

totten commented Feb 28, 2020

I love the critical evaluation of the effect on real sites. In this case, I don't think it matters. civicrm_data.tpl is only used during the initial installation - for a normal site, it's one-off. Unit-tests are odd in that they periodically reset everything and have some narrow carve-outs. I can't think of any other scenario where the difference between INSERT / INSERT IGNORE (for this line) could matter.

Within the unit-testing world, I think I see/agree with @demeritcowboy's point about disabling. Suppose (hypothetically) you have complementary tests WithSequentialTest and WithoutSequentialTest. One test relies on a default (sequentialcreditnotes enabled), and the other test opts-out (disabling sequentialcreditnotes).

You would find that the tests were flaky/order-sensitive - because the INSERT IGNORE doesn't fully reset us back to baseline.

Generally INSERT ... ON DUPLICATE UPDATE does sound more correct. If for some reason the uniquess constraints aren't suitable, DELETE ... WHERE plus INSERT would probably have the desired effect too.

@eileenmcnaughton
Copy link
Contributor

@totten at this stage the position is that core extensions are part of core & we only test with them enabled. We merged to docs to that effect https://docs.civicrm.org/dev/en/latest/extensions/

@eileenmcnaughton eileenmcnaughton merged commit fcb28b1 into civicrm:master Feb 28, 2020
@eileenmcnaughton eileenmcnaughton deleted the extension_notices branch February 28, 2020 22:16
@eileenmcnaughton
Copy link
Contributor

merging this - it solves the problem for now - this is an evolving area that we will hopefully make more generic as we move more code but for now this helps us get to the end of the beginning of the beginning

@totten
Copy link
Member

totten commented Feb 28, 2020

Sure, if sequentialcreditnotes is hidden, that works for now.

But extracting this functionality in an extension signals a long-term intention to allow the system to work with the toggle going either way (on or off), right? That was the purpose of extracting it to an extension? Eventually you'll want some amount of test-coverage for both situations (where the toggle is on and off)

@eileenmcnaughton
Copy link
Contributor

@totten the point of extracting stuff is more about making the code more readable & more modular. Yes it WILL work with sequentialcreditnotes off -(and yes I will disable it for my sites) but the problem with this &a bunch of other features are the way they are integrated into the code (hacks on the forms, spaghetti deep in the BAO) makes our code un-fixable.

To look at the order api - it's not where it should be and that's largely because of add-on-features (this was one) embedded deeply into code that we need to make sensible in order to make it ready to support afform.

@eileenmcnaughton
Copy link
Contributor

"Eventually you'll want some amount of test-coverage for both situations (where the toggle is on and off)" - at the moment we have only figured out where to add coreextensions in to make them be tested & installed & added on upgrade - we need to make all of those things generic before that eventually happens so they all need to be revisited

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.

4 participants