-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Upgrade scripts disable foreign key checks #9694
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
Comments
@jantzenw, thank you for your report. |
@jantzenw, just for information, there was a blogpost about this issue on Magento's Devblog a couple of weeks after you created this issue: https://community.magento.com/t5/Magento-DevBlog/Mysterious-startSetup-and-endSetup-Methods/ba-p/68483 Unfortunately, I've seen them being used all over the place, in third party extensions, in tutorials, in blogposts, and I've used them myself because I thought you were supposed to use them, ... |
I'll take this one #squashtoberfest |
@lfolco please accept the invite to magento2 repo |
So to confirm the purpose of this ticket is to remove the foreign key checks? Should we consider adding any new methods that add the foreign key checks in case someone needs them? |
Perhaps nothing should change and developers should simply not call Perhaps it could be less misleading, possibly by deprecating these functions and replacing their logic with functions named like this:
|
I agree with @jantzenw, these methods "sound necessary" due to their awful naming:
|
@jantzenw We are closing this issue now, as this seems to be a correct behavior. |
@magento-engcom-team it's a "correct behaviour" but that's not the point on this one, the fact is it is a misleading method that should be refactored as per the suggestion from @jantzenw - is this in progress or is this issue now "resolved" because its not a bug per se? |
@josephmcdermott & @jantzenw: if you want these things to happen, I think it's best if you submit a PR with the changes you guys are suggesting, PR's are getting much more attention from the Magento devs then discussions in issues unfortunately. |
…nline-deployment Benagls ACQE functional deployment
Magento\Framework\DB\Adapter\Pdo\Mysql::startSetup
is disabling foreign key checks, causing deletions in upgrade scripts to not propagate. This behavior was introduced in Magento CE 1.6 (August 2011) and should be revisited.Preconditions
Magento CE 2.1.6 for below example, but the behavior seems to have existed since Magento CE 1.6+.
Steps to reproduce
This can be reproduced with deletion of any entity in an upgrade script, but here is one example:
Expected result
The customer group is deleted, along with all database entries that have a foreign key on this customer group. This includes entries in tables like
catalog_product_price_index
,catalog_product_index_price_idx
,catalogrule_customer_group
andsalesrule_customer_group
, among others.Actual result
The customer group is deleted, but entries remain in the above tables with foreign keys, causing severe downstream issues. Using the above example, deleting a customer group causes errors when saving products because a foreign key constraint fails:
Root Cause
The issue is ultimately due to this code:
startSetup
disables foreign key checks.Workaround
Enable foreign key checks before deleting the entities in the upgrade script:
Summary
It seems that disabling foreign key checks should be the responsibility of the developer writing the upgrade script, because it would be immediately obvious that they would need to do so to get their script to complete. With the current behavior, unaware developers can delete data with foreign keys disabled, possibly causing severe issues that are not immediately noticeable and are far downstream from the root cause.
This unexpected behavior can cause severe issues and should be discussed. If it is not possible to modify this behavior, an explanation would be appreciated.
The text was updated successfully, but these errors were encountered: