Skip to content

[Fixed: #31396] Data/Schema Patches getAliases() not working as expected #37682

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

Closed
wants to merge 17 commits into from

Conversation

MatthijsBreed
Copy link

@MatthijsBreed MatthijsBreed commented Jun 28, 2023

Description (*)

This PR fixed next issues #31396 #23031

This PR is a continuation of work in PR 31635 (#31635) to account for every patch alias that might be already applied and to persist any new patch aliases

Fixed Issues (if relevant)

#31396 #23031

Testing Scenario

1. Create new Data Patch and apply via bin/magento setup:upgrade

2. See that patch is added to patch_list in the database

3. Rename Data Patch file and add old name to aliases

4. Re-run bin/magento setup:upgrade

5. See that the new patch name is added to path_list but the apply() function has not been called

@m2-assistant
Copy link

m2-assistant bot commented Jun 28, 2023

Hi @MatthijsBreed. Thank you for your contribution!
Here are some useful tips on 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
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@MatthijsBreed
Copy link
Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Bravo engcom-Bravo added the Priority: P3 May be fixed according to the position in the backlog. label Jun 28, 2023
@@ -24,6 +24,7 @@
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\SetupInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use phpDocumentor\Reflection\Types\True_;
Copy link
Member

Choose a reason for hiding this comment

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

this can be removed, or not?

Suggested change
use phpDocumentor\Reflection\Types\True_;

@@ -296,4 +292,38 @@ public function revertDataPatches($moduleName = null)
}
}
}

/**
* Checks if patch should be applied by already applied patch alias names
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Checks if patch should be applied by already applied patch alias names
* Check if patch should be applied by already applied patch alias names

if ($patch = $patch->getAliases()) {
foreach ($patch as $patchAlias) {
if ($this->patchHistory->isApplied($patchAlias)) {
$shouldApply = false;
Copy link
Member

Choose a reason for hiding this comment

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

variable assigning is not necessary, you can use return directly

@MatthijsBreed
Copy link
Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@MatthijsBreed
Copy link
Author

@magento run Unit Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@MatthijsBreed
Copy link
Author

@sippsolutions , thank you for your feedback.

I have checked all failing tests, but after the last commit, the only tests that are failing are urelated functionalities, are these blocking for this PR or is there another way to resolve them?

Unit Tests fail on 'Magento\CatalogGraphQl\Test\Unit\DataProvider\Product\SearchCriteriaBuilderTest::testBuild'

Functional tests fail on "Magento\AcceptanceTest_InventorySingleModeSuite_0_G\Backend\StorefrontValidateVisualSwatchAbsenceOfAttributeWhenProductStocksOutTestCest::StorefrontValidateVisualSwatchAbsenceOfAttributeWhenProductStocksOutTest" and "Magento\AcceptanceTest_default\Backend\AdminApplyChangePriceForConfigurableProductWithAssignedSimpleProductsTestCest::AdminApplyChangePriceForConfigurableProductWithAssignedSimpleProductsTest"

Webapi tests fail on 'Magento\GraphQl\Catalog\ProductSearchTest::testFilterProductsBySingleCategoryId'

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Hotel
Copy link
Contributor

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Hotel
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests EE, Functional Tests CE, Integration Tests, Unit Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

Copy link
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

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

Hello @MatthijsBreed,

Thanks for the contribution!

Code changes look good to me and failed tests seem flaky.

Hence approving this PR.

@engcom-Lima engcom-Lima added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Sep 25, 2023
@engcom-Echo engcom-Echo self-assigned this Sep 26, 2023
@engcom-Echo
Copy link
Contributor

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Echo
Copy link
Contributor

engcom-Echo commented Sep 27, 2023

@MatthijsBreed,

We are not able to reproduce the issue.
Can you please confirm the issue still exist on 2.4-develop?

To Reproduce the issue we have followed below steps.

  1. Create new Data Patch and apply via bin/magento setup:upgrade
  2. See that patch is added to patch_list in the database
  3. Rename Data Patch file and add old name to aliases
  4. Re-run bin/magento setup:upgrade
  5. Patch gets applied successfully.

Also please refer to this abc8e696.

Lets us know if you are still facing the issue on 2.4-develop with detailed steps.

Moving it to on hold

@MatthijsBreed
Copy link
Author

@engcom-Echo

The reproduction steps you described you described are the problem this PR aims to solve.
The commit you linked is only a check for possibly writing duplicate aliases to the database AFTER the patch has been applied.

Current (incorrect) situation:

  • Create a patch called 'A' with no aliases
  • Run bin/magento setup:upgrade, patch A gets applied and 'A' is added to the patch_list table
  • Rename patch A to 'B'
  • Add 'A' to the aliases
  • Run bin/magento setup:upgrade again, patch A gets applied again and 'B' is added to the patch_list table

Desired situation:

  • Create a patch called 'A' with no aliases
  • Run bin/magento setup:upgrade, patch A gets applied and 'A' is added to the patch_list table
  • Rename patch A to 'B'
  • Add 'A' to the aliases
  • Run bin/magento setup:upgrade again, patch A is not applied and 'B' is added to the patch_list table

Please see the PR description and the issues linked therein

@engcom-Echo
Copy link
Contributor

engcom-Echo commented Sep 27, 2023

@MatthijsBreed

I have followed the step mentioned here

Before PR

  1. Create a patch called 'ExampleDataPatch' with no aliases
class ExampleDataPatch implements DataPatchInterface
{
    /**
     * @var ModuleDataSetupInterface
     */
    private $moduleDataSetup;


    /**
     * @var LoggerInterface
     */
    private $logger;

    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup,
        LoggerInterface $logger
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->logger = $logger;
    }
    
    public function apply()
    {
        $this->moduleDataSetup->startSetup();
        $this->logger->info('ExampleSchemaPatch: Apply method executed.');
        $this->moduleDataSetup->endSetup();
    }
    
    public static function getDependencies()
    {
        return [];
    }
    
    public function getAliases()
    {
        return [];
    }
}
  1. Run bin/magento setup:upgrade, patch ExampleDataPatch gets applied and 'ExampleDataPatch' is added to the patch_list table
  2. Rename patch ExampleDataPatch file and class name to 'ChangedExampleDataPatch'
  3. Add 'ExampleDataPatch' to the aliases
public function getAliases()
    {
        return [
            ExampleDataPatch::Class
        ];
    }
  1. Run bin/magento setup:upgrade again, patch ExampleDataPatch gets applied again verfied from log file and 'ChangedExampleDataPatch' is added to the patch_list table
Screenshot 2023-09-27 at 5 02 40 PM

After PR Changes

  1. Follow step 1-6 as above case
  2. Run bin/magento setup:upgrade again, patch ExampleDataPatch not applied again verfied from log file. But ChangedExampleDataPatch is not added to the patch_list table
Screenshot 2023-09-27 at 5 06 43 PM

Let us know if we have missed anything here.

@engcom-Echo
Copy link
Contributor

@MatthijsBreed can you please have a look at comment and suggest if we are missing anything here?

@engcom-Echo
Copy link
Contributor

@MatthijsBreed did you get time to have a look at comment ?

@engcom-Charlie
Copy link
Contributor

Hi @MatthijsBreed,

Thank you for your contribution!

As mentioned here, please have a look and let us know if we are missing anything.

Till then closing this PR. Please feel free to reopen it as you want to update further.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P3 May be fixed according to the position in the backlog. Project: Community Picked PRs upvoted by the community Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants