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

Adds missing return value in afterSave plugin. #29035

Merged
merged 3 commits into from
Aug 8, 2020

Conversation

hostep
Copy link
Contributor

@hostep hostep commented Jul 8, 2020

Description (*)

All after plugins should always return a value, so other plugins which follow them in the stack get the correct input parameters instead of null.
It appears that in MC-18561 this was forgotten and this can cause crashes when the sort order of default Magento modules are different then in a vanilla installation (which can happen after installing certain custom modules)

See #29034 for more information

The bug was introduced in Magento 2.3.4, so it makes sense if this PR is considered to be backported to 2.3 as well

I have no interest in adding additional automatic tests for this and wouldn't even know how to approach this, so if this is required, somebody else will need to take care of this.

Thanks!

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Missing return value in Magento\CmsUrlRewrite\Plugin\Cms\Model\Store\View::afterSave can cause saving a storeview to crash #29034

Manual testing scenarios (*)

See #29034

Questions or comments

Not sure if this is possible, but having a static analyser test to detect after plugins without return values could have prevented this mistake to have entered the code base

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jul 8, 2020

Hi @hostep. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

@hostep
Copy link
Contributor Author

hostep commented Jul 8, 2020

@magento run all tests

@ihor-sviziev ihor-sviziev self-assigned this Jul 9, 2020
@ihor-sviziev ihor-sviziev added Award: bug fix Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. labels Jul 9, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Hi @hostep,
Your changes looks good. Could you cover them with unit test?

@ihor-sviziev ihor-sviziev added Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests and removed Progress: needs update labels Jul 9, 2020
@hostep
Copy link
Contributor Author

hostep commented Jul 9, 2020

Hi @ihor-sviziev, please re-read my opening post, sorry I simply don't have the time for tests (if it takes me 5 to 10 times longer to write tests then to write a fix, I'm not going to do it, really sorry).

@ihor-sviziev
Copy link
Contributor

@hostep got it, I just missed point related to tests.

@engcom-Charlie @engcom-Kilo @engcom-Golf could you help covering this case with unit tests?

@engcom-Charlie engcom-Charlie self-assigned this Jul 9, 2020
@engcom-Charlie
Copy link
Contributor

@magento run all tests

@ihor-sviziev ihor-sviziev added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Jul 9, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

✔ Approved.

Failing tests looks not related to changes form this PR.

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-7814 has been created to process this Pull Request

@engcom-Alfa engcom-Alfa self-assigned this Jul 10, 2020
@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Manual testing scenario:

  1. Setup a vanilla Magento installation
  2. In the backend, go to Stores > All Stores
  3. Open the 'Default Store View'
  4. Save the storeview, no need to change anything, notice that this works fine
  5. Now simulate we installed a bunch of custom modules which changes the sort order of certain Magento modules in the app/etc/config.php file, so manually change that file so Magento_CatalogUrlRewrite comes later then Magento_CmsUrlRewrite:
--- app/etc/config.php	2020-07-08 11:42:38.000000000 +0200
+++ app/etc/config2.php	2020-07-08 11:42:35.000000000 +0200
@@ -30,7 +30,6 @@
         'Magento_Payment' => 1,
         'Magento_CatalogRuleGraphQl' => 1,
         'Magento_CatalogRule' => 1,
-        'Magento_CatalogUrlRewrite' => 1,
         'Magento_StoreGraphQl' => 1,
         'Magento_Widget' => 1,
         'Magento_Quote' => 1,
@@ -39,6 +38,7 @@
         'Magento_CmsGraphQl' => 1,
         'Magento_EavGraphQl' => 1,
         'Magento_CmsUrlRewrite' => 1,
+        'Magento_CatalogUrlRewrite' => 1,
         'Magento_CmsUrlRewriteGraphQl' => 1,
         'Magento_User' => 1,
         'Magento_Msrp' => 1,
  1. Flush the caches: bin/magento cache:flush (do not run bin/magento setup:upgrade because it will revert the changes you just did)
  2. In the backend, go to Stores > All Stores and open the 'Default Store View' again
  3. Save the storeview again

Before: ✖️ Throws the following error:

Screenshot from 2020-07-10 09-51-49

After: ✔️ Store view gets saved without errors and plugin returns a value, in this case Magento\CmsUrlRewrite\Plugin\Cms\Model\Store\View::aftersSave is missing one

Screenshot from 2020-07-10 11-40-56

@engcom-Charlie engcom-Charlie added the QA: Ready to add to Regression Scope Should be analyzed and added to Regression Testing Scope(if applicable) label Jul 10, 2020
@engcom-Alfa engcom-Alfa added QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope and removed QA: Ready to add to Regression Scope Should be analyzed and added to Regression Testing Scope(if applicable) labels Aug 3, 2020
@ghost ghost added Progress: accept Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S1 Affects critical data or functionality and forces users to employ a workaround. and removed Progress: extended testing Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. labels Aug 4, 2020
@magento-engcom-team magento-engcom-team merged commit edba696 into magento:2.4-develop Aug 8, 2020
@m2-assistant
Copy link

m2-assistant bot commented Aug 8, 2020

Hi @hostep, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Component: CmsUrlRewrite Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S1 Affects critical data or functionality and forces users to employ a workaround.
Projects
Archived in project
5 participants