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

Scope bug in Catalog URL resource (_getCategories) #38393

Open
pmzandbergen opened this issue Jan 29, 2024 · 8 comments · May be fixed by #38394
Open

Scope bug in Catalog URL resource (_getCategories) #38393

pmzandbergen opened this issue Jan 29, 2024 · 8 comments · May be fixed by #38394
Assignees
Labels
Area: Catalog Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR in progress Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@pmzandbergen
Copy link
Contributor

pmzandbergen commented Jan 29, 2024

Bug
The following condition is obviously invalid:

$isActiveExpr = $connection->getCheckSql('c.value_id > 0', 'c.value', 'c.value');

Explanation
The resulting query is:

SELECT
`main*table\`.`entity*id`,
`main*table\`.`parent*id`,
`main_table\`.`level`,
IF(c.value*id > 0, c.value, c.value) AS `is*active`,
`main_table\`.`path`
FROM
`catalog*category_entity\` AS `main*table`
LEFT JOIN `catalog*category_entity_int\` AS `d` ON d.attribute_id = 46 AND d.store_id = 0 AND d.entity_id = main_table.entity*id
LEFT JOIN `catalog*category_entity_int\` AS `c` ON c.attribute_id = 46 AND c.store_id = 3 AND c.entity_id = main_table.entity*id
WHERE (main*table.entity*id IN(...))

Attribute is_active\ is joined twice on both the store (c\) and default scope (d\). If there is no value available on the store scope (c.value\) the default scope (d.value) should be used instead.

Solution
The condition from line 415:

$isActiveExpr = $connection->getCheckSql('c.value_id > 0', 'c.value', 'c.value');

Should be changed to:

$isActiveExpr = $connection->getCheckSql('c.value_id IS NOT NULL', 'c.value', 'd.value');

 

Note: This bug might not be affecting any Magento code (depends if the is_active flag is actually being used somewhere).

Copy link

m2-assistant bot commented Jan 29, 2024

Hi @pmzandbergen. 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. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ 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.

pmzandbergen added a commit to pmzandbergen/magento2 that referenced this issue Jan 29, 2024
@engcom-Dash engcom-Dash added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Jan 29, 2024
@engcom-Bravo engcom-Bravo added the Reported on 2.4.x Indicates original Magento version for the Issue report. label Jan 29, 2024
@pmzandbergen pmzandbergen linked a pull request Jan 29, 2024 that will close this issue
5 tasks
@andrewbess
Copy link

Hello @sidolov
I've checked fixes from this PR and researched history of the fixed logic.
This logic is more than 12 years old.
It looks like this logic was migrated from Magento1.
I am sure this fixes can affect a lot of Magento-projects, 3rd-party extensions, etc, which may be depend on results of it.
So, I think we need to discuss it on the guild.
Could you please create an internal jira issue to discuss it on the necessary guild.

Thank you in advance.

@engcom-Hotel engcom-Hotel self-assigned this Feb 8, 2024
Copy link

m2-assistant bot commented Feb 8, 2024

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).
  • 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- 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 @pmzandbergen,

Thanks for the report and collaboration!

We have verified the issue by looking into the codebase:

$isActiveExpr = $connection->getCheckSql('c.value_id > 0', 'c.value', 'c.value');

This statement does not make any sense if in any case, we need to use c.value. Either we need to remove the condition or replace the condition as below:

$isActiveExpr = $connection->getCheckSql('c.value_id > 0', 'c.value', 'd.value');

Hence confirming the issue.

Thanks

@engcom-Hotel engcom-Hotel added Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Area: Catalog and removed Issue: ready for confirmation labels Feb 8, 2024
@github-jira-sync-bot
Copy link

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

Copy link

m2-assistant bot commented Feb 8, 2024

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

@andrewbess
Copy link

This statement does not make any sense if in any case, we need to use c.value. Either we need to remove the condition or replace the condition as below:

$isActiveExpr = $connection->getCheckSql('c.value_id > 0', 'c.value', 'd.value');

Hence confirming the issue.

Thanks

Hello @engcom-Hotel

I am not sure we need to change results of the SQL query by we-self without discussing with product's owners or platform's architects.
This logic is 12 years old and changes can provoke unexpected problem for a lot of projects after platform upgrade.
I would propose remove this redundant condition.
Anyway, you need to discuss it internally in Adobe (the jira issue already created).
Let's do it.

Thank you in advance.

cc @maghamed

@pmzandbergen
Copy link
Contributor Author

pmzandbergen commented Feb 8, 2024

Hello @pmzandbergen,

Thanks for the report and collaboration!

We have verified the issue by looking into the codebase:

$isActiveExpr = $connection->getCheckSql('c.value_id > 0', 'c.value', 'c.value');

This statement does not make any sense if in any case, we need to use c.value. Either we need to remove the condition or replace the condition as below:

$isActiveExpr = $connection->getCheckSql('c.value_id > 0', 'c.value', 'd.value');

Hence confirming the issue.

Thanks

Hi @engcom-Hotel,

My PR is using a different condition (IS NULL instead of > 0) with a small but significant difference outcome:

c.value d.value > 0 IS NULL Comment
NULL 0 0 0 OK
NULL 1 1 1 OK
0 0 0 0 OK
0 1 1 0 Unexpected result when using > 0
1 0 1 1 OK
1 1 1 1 OK

Please ensure the correct fix is used (see my PR @ #38394 )

@engcom-Hotel engcom-Hotel moved this to Pull Request In Progress in High Priority Backlog Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Catalog Component: Catalog Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR in progress Reported on 2.4.x Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Pull Request In Progress
Development

Successfully merging a pull request may close this issue.

6 participants