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

The unsigned flag is not recognized on schema parsing and comparison on MySQL 8.0.30 #36558

Closed
1 of 5 tasks
speller opened this issue Dec 2, 2022 · 12 comments
Closed
1 of 5 tasks
Assignees
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.5 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@speller
Copy link

speller commented Dec 2, 2022

Preconditions and environment

  • Magento version 2.4.5
  • MySQL version 8.0.30

Steps to reproduce

Sample table

CREATE TABLE `yotpo_orders_sync` (
  `entity_id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity ID',
  `order_id` int unsigned NOT NULL COMMENT 'Order ID',
  `yotpo_id` double unsigned DEFAULT '0' COMMENT 'Yotpo ID',
  `synced_to_yotpo` datetime DEFAULT NULL COMMENT 'Synced to Yotpo',
  `response_code` varchar(5) DEFAULT NULL COMMENT 'Response Code',
  `is_fulfillment_based_on_shipment` tinyint(1) DEFAULT NULL COMMENT 'Fulfillment Sync Method',
  PRIMARY KEY (`entity_id`),
  UNIQUE KEY `YOTPO_ORDERS_SYNC_ORDER_ID` (`order_id`),
  KEY `YOTPO_ORDERS_SYNC_ENTITY_ID` (`entity_id`),
  KEY `YOTPO_ORDERS_SYNC_IS_FULFILLMENT_BASED_ON_SHIPMENT` (`is_fulfillment_based_on_shipment`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='Orders sync with Yotpo'

See the yotpo_id field definition.

Sample Magento definition:

        <column xsi:type="double" name="yotpo_id" unsigned="true" nullable="true" scale="0" default="0"
                comment="Yotpo ID"/>

Expected result

Magento successfully syncs database and declarative schema

Actual result

Magento doesn't recognize the unsigned flag.
Thus, the declarative schema is ALWAYS not up-to-date.

Additional information

The Magento\Framework\Setup\Declaration\Schema\Db\MySQL\DbSchemaReader::readColumns() method gets the following data for the yotpo_id field:

image

And then, since the \Magento\Framework\Setup\Declaration\Schema\Dto\ElementFactory::castGenericAttributes() expects the unsigned flag to be a separate array value, the unsigned flag is never detected and set properly:

image

The \Magento\Framework\ObjectManager\Factory\AbstractFactory::getResolvedArgument() method expects the unsigned flag to be in the array. If not, it picks the default false value:

image

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.
  • 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”.
@m2-assistant
Copy link

m2-assistant bot commented Dec 2, 2022

Hi @speller. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

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

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

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

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


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

🕙 You can find the schedule on the Magento Community Calendar page.

📞 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.

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

@speller
Copy link
Author

speller commented Dec 2, 2022

As a workaround, I'm using the following patch with the cweagans/composer-patches to fix the issue:

--- a/Setup/Declaration/Schema/Dto/ElementFactory.php
+++ b/Setup/Declaration/Schema/Dto/ElementFactory.php
@@ -60,6 +60,11 @@
     {
         $booleanAttributes = ['nullable', 'unsigned', 'identity'];

+        if (isset($elementStructuralData['definition']) && strpos($elementStructuralData['definition'], ' unsigned') > 0)
+        {
+            $elementStructuralData['unsigned'] = true;
+        }
+
         foreach ($booleanAttributes as $booleanAttribute) {
             if (isset($elementStructuralData[$booleanAttribute])) {
                 $elementStructuralData[$booleanAttribute] = $this->booleanUtils

@engcom-Hotel engcom-Hotel added Reported on 2.4.5 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it labels Dec 5, 2022
@engcom-Hotel engcom-Hotel self-assigned this Dec 27, 2022
@m2-assistant
Copy link

m2-assistant bot commented Dec 27, 2022

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: 👇

  • 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.

@engcom-Hotel
Copy link
Contributor

Hello @speller,
Thanks for the reporting and collaboration!

We have tried to reproduce the issue in Magento 2.4-develop branch but the issue is not reproducible for us. We are able to run the below command after creating the custom module for table creation:

bin/magento setup:upgrade

The definition of the db_schema.xml is as follows:

<?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="issue_36558" resource="default" engine="innodb" comment="Issue 36558">
        <column
            xsi:type="double"
            name="entity_id"
            unsigned="true"
            nullable="true"
            default="0" comment="Entity ID"/>
    </table>
</schema>

We can see the table is created with the given definition above:

image

Please let us know if we have missed anything.

Thanks

@engcom-Hotel engcom-Hotel added Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: needs update Additional information is require, waiting for response labels Dec 27, 2022
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Dec 27, 2022
@m2-community-project m2-community-project bot removed Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: ready for confirmation labels Dec 27, 2022
@speller
Copy link
Author

speller commented Dec 28, 2022

@engcom-Hotel does the setup:db:status command detect changes right after the setup:upgrade command in your case?

@engcom-Hotel
Copy link
Contributor

Hello @speller,

Thanks for the reply!

We have checked the output of setup:db:status but it is saying Declarative Schema is not up to date:

image

But I have we have checked the setup:db:status with fresh installation without the above custom module, but we are still getting the same result as Declarative Schema is not up to date.

I think there is an issue related to this here which is confirmed #35671.

Thanks

@speller
Copy link
Author

speller commented Dec 29, 2022

@engcom-Hotel as I described in the ticket, this issue exists in my setup in addition to #35671.
To confirm the issue, could you check whether the Magento\Framework\Setup\Declaration\Schema\Db\MySQL\DbSchemaReader::readColumns() method returns the unsigned flag for the issue_36558.entity_id column when you perform the setup:db:status command?

@engcom-Hotel
Copy link
Contributor

Yes @speller,

By using the above Magento\Framework\Setup\Declaration\Schema\Db\MySQL\DbSchemaReader::readColumns(), we are getting the unsigned flag. We have the output as below:

Array
(
    [entity_id] => Array
        (
            [name] => entity_id
            [default] => 0
            [type] => double
            [nullable] => 1
            [definition] => double unsigned
            [extra] => 
            [comment] => Entity ID
        )

)

Thanks

@engcom-Hotel
Copy link
Contributor

Dear @speller,

We have noticed that this issue has not been updated for a period of 14 Days. Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket or reopen this ticket if you need more assistance on this.

Regards

@speller
Copy link
Author

speller commented Jan 17, 2023

@engcom-Hotel you don't have the unsigned flag in the array, isn't it? As I mentioned earlier, the Magento\Framework\Setup\Declaration\Schema\Dto\ElementFactory::castGenericAttributes() method expects the unsigned flag to be a separate array key. In your example, the array doesn't have the unsigned key.

@engcom-Hotel
Copy link
Contributor

Hello @speller,

It has an unsigned flag. You can see this in the definition here at the #36558 (comment).

Thanks

@speller
Copy link
Author

speller commented May 25, 2023

@engcom-Hotel no, the flag is in the definition value, but it should be a separate array key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Reported on 2.4.5 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

No branches or pull requests

2 participants