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

Mage_Core_Model_Abstract: Fix rollback when Throwable is thrown in save/delete method #1483

Merged
merged 2 commits into from
Apr 29, 2021

Conversation

Sekiphp
Copy link
Contributor

@Sekiphp Sekiphp commented Mar 3, 2021

Description (*)

When you throw some child of Error class (or Error class) in _beforeSave or in _afterSave methods - Magento do not rollback started transaction and it is provide error:
image

PHP implementation:
Error implements Throwable
Exception implements Throwable

Manual testing scenarios (*)

Consider this code:

class Namespace_Module_Model_Foo extends Mage_Core_Model_Abstract {
    protected function _beforeSave()
    {
        parent::_beforeSave();

        throw new Error('error from some specifiec reason');
    }
}

Mage::getModel('namespace_module/foo')->save();

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

@github-actions github-actions bot added the Component: Core Relates to Mage_Core label Mar 3, 2021
midlan
midlan previously approved these changes Mar 4, 2021
@LukasCesal
Copy link
Contributor

Funny when you are upgrading to LTS and get another bunch of errors :-) thank you Luboš

@kiatng
Copy link
Contributor

kiatng commented Mar 9, 2021

See also PR #1442

@Sekiphp
Copy link
Contributor Author

Sekiphp commented Mar 9, 2021

@kiatng Yeah, I seen it. But we should merge this pull request first - less code, less potentional breaking. This is tested on our OpenMage instance and solving real issue, which is described here.

@kiatng
Copy link
Contributor

kiatng commented Mar 10, 2021

@Sekiphp First, as you said, you have already fixed this in your project. Others facing similar issue can likewise fix them in their respective projects, no issue there. Second, for maintaining OpenMage code base, we need to fix Throwable for all instances, this helps to maintain code quality in terms of consistency, eg, use of $t or $e. We can better progress OpenMage this way. I hope you agree.

Copy link
Member

@colinmollenhour colinmollenhour left a comment

Choose a reason for hiding this comment

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

Good change! Thanks for the PR!

nitpick: Please fix the vardoc and delete() as well while you're at it.

LukasCesal
LukasCesal previously approved these changes Mar 18, 2021
@Sekiphp Sekiphp dismissed stale reviews from LukasCesal and midlan via 83a85e8 April 6, 2021 15:34
@Sekiphp Sekiphp changed the title Mage_Core_Model_Abstract: Fix rollback when Throwable is thrown in save method Mage_Core_Model_Abstract: Fix rollback when Throwable is thrown in save/delete method Apr 6, 2021
@Sekiphp
Copy link
Contributor Author

Sekiphp commented Apr 6, 2021

@colinmollenhour Added throws annotation and fixed delete() method

  • I changed Throwable $t to Throwable $e, because I read the specifications, and in official PHP examples is $e instead of $t:

@Flyingmana Flyingmana merged commit 3c9fb54 into OpenMage:1.9.4.x Apr 29, 2021
@github-actions
Copy link
Contributor

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
6 runs  +4  4 ✔️ +2  0 💤 ±0  2 ❌ +2 

Results for commit 3c9fb54. ± Comparison against base commit 0e2f81d.

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

Successfully merging this pull request may close these issues.

6 participants