magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

migrateDataFromAnotherTable() does not work for declarative schema

Open DmitryFurs opened this issue 2 years ago • 17 comments

Preconditions

  1. Magneto Community Edition 2.4.3-p1

Steps to reproduce

  1. Create a table using a declarative schema
  2. run setup:upgrade
  3. Add rows to the created table
  4. Rename the table using migrateDataFromAnotherTable() in the declarative schema
  5. run setup:upgrade again

Expected result

  1. Table with a new name has been created
  2. Data from the table with the previous name is copied to the table with the new name

Actual result

  1. Table with a new name has been created
  2. Data is not copied to the new table

Additional Info

During the investigation, it was found that the vertexinc/module-tax module was installed together with Magneto.

This module adds its own trigger to create a table in a declarative schema image

When you breakpoint in the Magento\Framework\Setup\Declaration\Schema\Operations\CreateTable class, you can see that the trigger added in app/etc/di.xml is missing from the list of added ones, and there is only vertexinc present there image

After vertexinc was commented out image

and the setup:upgrade started again, vertexinc disappeared and migrateDataFromAnotherTable appeared image

After the setup:upgrade was completed, the rows were copied to the new table.

Most likely the reason lies somewhere in the merger app/etc/di.xml and others di.xml files, in our case it is vendor/vertexinc/module-tax/etc/di.xml


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

DmitryFurs avatar Oct 20 '21 15:10 DmitryFurs

Hi @DmitryFurs. Thank you for your report. To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

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

Please, add a comment to assign the issue: @magento I am working on this


:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] avatar Oct 20 '21 15:10 m2-assistant[bot]

@magento/ext-vertex please take a look at this issue.

ihor-sviziev avatar Oct 21 '21 06:10 ihor-sviziev

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Oct 21 '21 06:10 m2-assistant[bot]

This is the exact same issue I've described here https://github.com/magento/magento2/issues/26433 However, my issue got zero attention for over a year so I've closed it. Basically adding new arguments to types via di.xml overwrites the entire node. Hard to say it is desired or a bug, but it is safe to assume the XMLs are merged, as the rest of them (config.xml, cache.xml, routes.xml and so on) are in fact merged. Imho, it is a bug, but you can see the info about this in devdocs: https://devdocs.magento.com/guides/v2.4/extension-dev-guide/build/di-xml-file.html

qsolutions-pl avatar Oct 22 '21 19:10 qsolutions-pl

@maghamed @kandy, can you explain, why it was implemented in this way? is it a bug, or a feature?

ihor-sviziev avatar Oct 25 '21 09:10 ihor-sviziev

It was a feature when some one implemented his mind. But currently fix for one bug add two new bugs in different places 🤔

Den4ik avatar Oct 26 '21 13:10 Den4ik

@ihor-sviziev
Array items of DI configuration in the scope of the same area should be merged. It's a pretty important functionality for modularity and is used in multiple places, For example, \Magento\Framework\Console\CommandListInterface has ~ 30 places in different modules that add items in the common array argument.

I try to reproduce this issue and I do finely after some tries. So the issue can be reproduced only if DI compilation was not run, and only if the configuration is defined in a prime file (app/etc/env.php)

also please see https://github.com/magento/magento2/issues/3835#issuecomment-198473455

I prepared draft PR https://github.com/magento/magento2/pull/34457 that probably can fix this issue

kandy avatar Oct 27 '21 14:10 kandy

@kandy Will this also resolve the issue with invalid merging of Product Type configuration? For example when you want to change the flag refundable for virtual product type in product_types.xml

lbajsarowicz avatar Oct 27 '21 20:10 lbajsarowicz

@lbajsarowicz no, I think it unrelated issues

kandy avatar Oct 27 '21 22:10 kandy

Faced similar issue in DI when wanted to add new items in different area https://github.com/magento/magento2/issues/34464

ilnytskyi avatar Nov 04 '21 07:11 ilnytskyi

Is there any news here? Thanks!

DmitryFurs avatar Feb 22 '22 05:02 DmitryFurs

Hi @engcom-Delta. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Sep 19 '22 09:09 m2-assistant[bot]

Hi @DmitryFurs,

We have tried to reproduce this issue in 2.4-develop but for us, it is not reproducible.

We have followed below steps

1.Created catalogproducts table using a declarative schema Screenshot 2022-09-19 at 4 03 10 PM

2.Added rows to the catalogproducts table. Screenshot 2022-09-19 at 4 07 17 PM

3.Rename the table using migrateDataFromAnotherTable() as catalogproducts1 Screenshot 2022-09-19 at 4 08 47 PM

  1. Table with new name is created and the data are copied to renamed table.
    Screenshot 2022-09-19 at 4 09 40 PM

Please let us know if we are missing any steps here.

Thanks.

engcom-Delta avatar Sep 19 '22 13:09 engcom-Delta

@engcom-Delta The removal of VBEs resolved the symptom of the issue.

The real issue is the way di.xml is merged between the global app/etc/di.xml and module di.xmls (with module di.xml's replacing, instead of expanding, entries in app/etc/di.xml).

When this issue was created, Vertex added a schema trigger. Any module that does so will overwrite core schema triggers - which is not desirable.

navarr avatar Sep 19 '22 14:09 navarr

@engcom-Delta Yes, @navarr is right, the problem is that you can't add your own triggers. When merging from different areas, native triggers will be overridden, even if they have other unique names.

DmitryFurs avatar Sep 19 '22 17:09 DmitryFurs

@DmitryFurs ,@navarr We have tried to reproduce this issue in magento 2.4-develop still this issue is not reproducible with merging of di.xml files. In below document vertex is not bundled extension in latest versions. https://docs.magento.com/user-guide/tax/taxes.html Screenshot 2022-09-20 at 2 43 11 PM Please let us know if we are missed anything. Thanks.

engcom-Delta avatar Sep 20 '22 09:09 engcom-Delta

@engcom-Delta What should we do if we need to install the vertex module or any other that adds its own triggers? If this module is installed, the problem will reappear. How to fix the situation?

DmitryFurs avatar Sep 20 '22 18:09 DmitryFurs

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Nov 02 '22 09:11 m2-assistant[bot]

Hello @DmitryFurs @navarr,

We have tried to reproduce this issue in the Magento 2.4-develop as well as 2.4.5 by creating a custom module to create a table. We have followed the below steps with and without the Vertex module installed:

  1. Creating a module to create a table.
  2. Run bin/magento setup:db-declaration:generate-whitelist --module-name=Magz_Issue34394 command
  3. and then bin/magento s:up

With the Vertex module, we have the new table created but no data copied from the existing table but without that module the data is also copied.

We need to fix the way in which di.xml merges. So the issue seems in the Magento module. Hence confirming the issue.

Thanks

engcom-Hotel avatar Nov 02 '22 10:11 engcom-Hotel

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-6950 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Nov 02 '22 10:11 github-jira-sync-bot

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] avatar Nov 02 '22 10:11 m2-assistant[bot]

Hello @DmitryFurs @navarr,

We have discussed this issue with developers internally and come to the below conclusion:

As per the analysis for the issue, the vertexinc/vertex-tax-module:4.2.8 di.xml is an area-specific configuration, and the app/etc/di.xml is the initial one. As per devdocs the area-specific config will override the initial one so this is expected behavior. we can check further Here.

We have one different example as well to demonstrate the expected behavior of DI. vendor/magento/module-customer/etc/di.xml image

app/etc/di.xml image image

The module-specific configuration will override the same expected behavior.

Thanks

engcom-Hotel avatar Nov 24 '22 13:11 engcom-Hotel

@engcom-Hotel I think everyone in this thread understands that's the expected behavior of XML merge as it exists today

However, I think the point of the ticket is that database triggers especially should not be disappear if a module tries to add one

This has two potential solutions to that regard:

  • Merge initial and area configuration instead of overwriting
  • Or Magento needs to host important configuration in an area configuration file

Personally, I've never understood why app/etc/di.xml exists or is treated differently.

navarr avatar Nov 24 '22 13:11 navarr

@engcom-Hotel I completely agree with @navarr

DmitryFurs avatar Dec 01 '22 12:12 DmitryFurs

Hello @navarr @DmitryFurs,

We are under discussion on this issue internally. Will keep you posted on this soon.

Thanks

engcom-Hotel avatar Dec 01 '22 13:12 engcom-Hotel

Moving this ticket "On hold"

engcom-Hotel avatar Dec 12 '22 05:12 engcom-Hotel

@engcom-Hotel @engcom-Echo any updates? Why task was closed w/o any comments?

ihor-sviziev avatar Sep 28 '23 07:09 ihor-sviziev

Hi @ihor-sviziev @DmitryFurs,

As per the Internal team they are not able to reproduce the issue hence they have closed jira form their side.

Thanks.

engcom-Bravo avatar Sep 28 '23 12:09 engcom-Bravo

Were there any changes made to the way di.xml entries are loaded, or did internal just give up on fixing this architectural issue?

navarr avatar Sep 28 '23 13:09 navarr