Skip to content

Fix SQL error throwed when websiteId is NULL #36802

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

Conversation

Sekiphp
Copy link

@Sekiphp Sekiphp commented Feb 3, 2023

Description (*)

In code is sometimes situation when $websiteId passed to addWebsiteGroupDateFilter is NULL.

Throwed error in GraphQL

image

Code

Problematic part:
image

Inside addWebsiteGroupDateFilter is called $this->addWebsiteFilter($websiteId);, but NULL for $websiteId is not problem there, because inside this method is this variable casted to int.
image

Manual testing scenarios (*)

  1. ...

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Fix SQL error throwed when websiteId is NULL #37284: Fix SQL error throwed when websiteId is NULL

@m2-assistant
Copy link

m2-assistant bot commented Feb 3, 2023

Hi @Sekiphp. Thank you for your contribution
Here are some useful tips 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 Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests 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 Pull Requests 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

@Sekiphp
Copy link
Author

Sekiphp commented Feb 3, 2023

@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 re-request them if they don't show in a reasonable amount of time.

@Sekiphp
Copy link
Author

Sekiphp commented Feb 6, 2023

@magento run Magento Health Index

@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 re-request them if they don't show in a reasonable amount of time.

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

hi @Sekiphp,
Your changes looks good. Could you please cover your change with some automated tests?

@ihor-sviziev ihor-sviziev added the Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. label Feb 7, 2023
@@ -332,13 +332,9 @@ public function addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now = n
'customer_group_ids.' .
$entityInfo['entity_id_field'] .
' = cgw.' .
$entityInfo['entity_id_field'] . ' AND ' . $websiteId . ' = cgw.website_id',
$entityInfo['entity_id_field'] . ' AND ' . (int) $websiteId . ' = cgw.website_id',
Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion there is not solving core of issue because it's looks like unpredictable application behavior.
Everywhere we expect to receive integer value of website id and we need to solve core of this problem specifically why website id is null.

@Sekiphp could you please add total list of steps for reproducing the error

Copy link
Author

Choose a reason for hiding this comment

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

@Den4ik It is truth. I was not able to simulate this error, but this part is problematic and I just use same solution, which is used in method, which is also called inside this method. In our website there are a lot of diferrent salesrules and probably not all are configured well and throws this error in some combination of steps.

Copy link
Contributor

@ihor-sviziev ihor-sviziev Feb 16, 2023

Choose a reason for hiding this comment

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

Hi @Sekiphp,
I just analyzed where this code is used - looks like it might be only in

foreach ($this->rssModel->getDiscountCollection($websiteId, $customerGroupId) as $rule) {

While website id is getting retrieved from store. In case when store doesn't have linked website - this will trigger such error.
$websiteId = $storeModel->getWebsiteId();

In this case, I think direct type conversion is good

@AshishKumarPundeer
Copy link
Contributor

@magento run Integration 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 re-request them if they don't show in a reasonable amount of time.

@engcom-Lima
Copy link
Contributor

@magento create issue

@engcom-Lima
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 re-request them if they don't show in a reasonable amount of time.

@engcom-Lima engcom-Lima removed their assignment Mar 24, 2023
@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 Mar 24, 2023
@engcom-Charlie engcom-Charlie self-assigned this Mar 28, 2023
@ihor-sviziev
Copy link
Contributor

@engcom-Charlie any updates on this?

@aissyass
Copy link

aissyass commented Dec 1, 2023

Hello @engcom-Lima @Sekiphp @Den4ik @ihor-sviziev
Any update please? We had the bug too!

@engcom-Charlie
Copy link
Contributor

@magento run all tests

thai2301 pushed a commit to thai2301/magento2 that referenced this pull request Sep 24, 2024
@engcom-Charlie
Copy link
Contributor

engcom-Charlie commented Sep 24, 2024

Hi @Sekiphp,

Thank you for your contribution!

Code wise the changes looks okay but we want to reproduce the issue in order to proceed further on the same.

In magento its not possible to have a store without a websiteId attached to it. We tried to reproduce this issue on local setup with different sections and tried to see when addWebsiteGroupDateFilter is getting used but no luck.

Can you please provide some more details on issue reproduction steps, till then moving this PR to On hold.

Thank you!

@engcom-Charlie
Copy link
Contributor

As mentioned here, we are unable to reproduce this issue hence closing this PR now.

Please feel free to reopen it for any further updates.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. 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.

[Issue] Fix SQL error throwed when websiteId is NULL
7 participants