magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Inconsistent escaping during database migration with MySQL

Open LouisdeLooze opened this issue 1 year ago • 8 comments

Preconditions and environment

  • Clean Magento 2.4.7-p3
  • Reproducible on MySQL 8, cannot be reproduced on MariaDB 10.6

Steps to reproduce

  1. Make custom module with a declarative schema that contains a PHP class as default. For example:
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="test_module_db" resource="default" engine="innodb">
        <column xsi:type="varchar" name="model" nullable="true" default="Test\\Module\\Model\\Default" comment="Corresponding Model"/>
    </table>
</schema>
  1. Run setup:upgrade
  2. Run setup:db:status

Expected result

No database migrations needed, just ran the migrations.

Actual result

Migration is needed (breaking zero-downtime deployments for no reason), this is the difference: from xml:

array(5) {
  ["type"]=>
  string(7) "varchar"
  ["nullable"]=>
  bool(true)
  ["default"]=>
  string(28) "Test\\Module\\Model\\Default"
  ["length"]=>
  int(255)
  ["comment"]=>
  string(19) "Corresponding Model"
}

from MySQL:

array(5) {
  ["type"]=>
  string(7) "varchar"
  ["nullable"]=>
  bool(true)
  ["default"]=>
  string(25) "Test\Module\Model\Default"
  ["length"]=>
  int(255)
  ["comment"]=>
  string(19) "Corresponding Model"
}

for reference, MariaDB:

array(5) {
  ["type"]=>
  string(7) "varchar"
  ["nullable"]=>
  bool(true)
  ["default"]=>
  string(25) "Test\\Module\\Model\\Default"
  ["length"]=>
  int(255)
  ["comment"]=>
  string(19) "Corresponding Model"
}

Additional information

No response

Release note

No response

Triage and priority

  • [ ] 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.
  • [X] 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”.

LouisdeLooze avatar Dec 17 '24 23:12 LouisdeLooze

Hi @LouisdeLooze. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.


Join Magento Community Engineering Slack and ask your questions in #github channel. :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, join the Community Contributions Triage session to discuss the appropriate ticket.

m2-assistant[bot] avatar Dec 17 '24 23:12 m2-assistant[bot]

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).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- 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 Dec 18 '24 15:12 m2-assistant[bot]

Hello @LouisdeLooze,

Thanks for the report and collaboration!

But we are unable to get the expected and actual result, request you to please elaborate on those.

Thanks

engcom-Hotel avatar Dec 18 '24 15:12 engcom-Hotel

Hi @engcom-Hotel

Directly after running setup:upgrade, running setup:db:status will output (does not matter how many times DB upgrade command is ran):

Declarative Schema is not up to date
Run 'setup:upgrade' to update your DB schema and data.

The extra output from above is when debugging \Magento\Framework\Setup\Declaration\Schema\Comparator::compare. I added the following before the return to show the differences between the sensitive parameters:

if (! (get_class($first) === get_class($second) &&
       $first->getDiffSensitiveParams() === $second->getDiffSensitiveParams())) {
       var_dump($first->getDiffSensitiveParams());
       var_dump($second->getDiffSensitiveParams());
}

And that shows the difference in escaping the backslashes, which makes the comparator think they are different. Resulting in a permanent state of the declarative schema being not up to date.

LouisdeLooze avatar Dec 18 '24 20:12 LouisdeLooze

Hello @LouisdeLooze,

Thanks for the report and collaboration!

We have tried to reproduce the issue in the latest 2.4-develop branch and the issue has been reproducible for us. Please refer to the screenshot below for reference:

image

The below module has been created by us to reproduce the issue: Issue39491.zip

Hence confirming the issue.

Thanks

engcom-Hotel avatar Dec 19 '24 14:12 engcom-Hotel

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

github-jira-sync-bot avatar Dec 19 '24 14:12 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 Dec 19 '24 14:12 m2-assistant[bot]

Hi @LouisdeLooze,

Adobe Commerce Engineering team started working on this issue. We will reach out to you if we need more information and you will get notified once the issue is fixed. Please leave comments for any further questions. Thank you!

engcom-Bravo avatar Dec 10 '25 11:12 engcom-Bravo