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

JoinProcessor caching issue #27504

Open
1 of 5 tasks
yutv opened this issue Mar 30, 2020 · 17 comments · May be fixed by #37550
Open
1 of 5 tasks

JoinProcessor caching issue #27504

yutv opened this issue Mar 30, 2020 · 17 comments · May be fixed by #37550
Assignees
Labels
Area: Order Component: Cache 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. Reported on 2.4.0 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

@yutv
Copy link

yutv commented Mar 30, 2020

Preconditions (*)

  1. Magento Open Source 2.4-develop
  2. PHP 7.3 - PHP 7.4

Steps to reproduce (*)

  1. Add a module with JoinProcessor for the OrderRepository using the files below:

    app/code/SomeVendor/SomeModule/registration.php
    <?php
    
    use Magento\Framework\Component\ComponentRegistrar;
    
    ComponentRegistrar::register(ComponentRegistrar::MODULE, 'SomeVendor_SomeModule', __DIR__);
    app/code/SomeVendor/SomeModule/etc/module.xml
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="SomeVendor_SomeModule" />
    </config>
    app/code/SomeVendor/SomeModule/etc/di.xml
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="Magento\Framework\Console\CommandListInterface">
            <arguments>
                <argument name="commands" xsi:type="array">
                    <item name="order:update" xsi:type="object">SomeVendor\SomeModule\Console\Command\OrderUpdate</item>
                </argument>
            </arguments>
        </type>
        <type name="SomeVendor\SomeModule\Console\Command\OrderUpdate">
            <arguments>
                <argument name="orderRepository" xsi:type="object">SomeVendor\SomeModule\Model\OrderRepository</argument>
            </arguments>
        </type>
        <virtualType name="SomeVendor\SomeModule\Model\OrderRepository" type="Magento\Sales\Model\OrderRepository">
            <arguments>
                <argument name="collectionProcessor" xsi:type="object">SomeVendor\SomeModule\Model\OrderRepository\CollectionProcessor</argument>
            </arguments>
        </virtualType>
        <virtualType name="SomeVendor\SomeModule\Model\OrderRepository\CollectionProcessor" type="Magento\Framework\Api\SearchCriteria\CollectionProcessor">
            <arguments>
                <argument name="processors" xsi:type="array">
                    <item name="joins" xsi:type="object">SomeVendor\SomeModule\Model\Api\SearchCriteria\CollectionProcessor\StoreViewJoinProcessor</item>
                </argument>
            </arguments>
        </virtualType>
        <virtualType name="SomeVendor\SomeModule\Model\Api\SearchCriteria\CollectionProcessor\StoreViewJoinProcessor" type="Magento\Framework\Api\SearchCriteria\CollectionProcessor\JoinProcessor">
            <arguments>
                <argument name="customJoins" xsi:type="array">
                    <item name="store.group_id" xsi:type="object">SomeVendor\SomeModule\Model\Api\SearchCriteria\JoinProcessor\Store</item>
                </argument>
            </arguments>
        </virtualType>
    </config>
    app/code/SomeVendor/SomeModule/Model/Api/SearchCriteria/JoinProcessor/Store.php
    <?php
    /**
     * Store Join Processor
     */
    declare(strict_types = 1);
    
    namespace SomeVendor\SomeModule\Model\Api\SearchCriteria\JoinProcessor;
    
    use Magento\Framework\Api\SearchCriteria\CollectionProcessor\JoinProcessor\CustomJoinInterface;
    use Magento\Framework\Data\Collection\AbstractDb;
    
    /**
     * Store Join Processor
     */
    class Store implements CustomJoinInterface
    {
        /**
         * @inheritDoc
         */
        public function apply(AbstractDb $collection)
        {
            $collection->join(
                ['store' => $collection->getResource()->getTable('store')],
                'store.store_id = main_table.store_id',
                []
            );
    
            return true;
        }
    }
    app/code/SomeVendor/SomeModule/Console/Command/OrderUpdate.php
    <?php
    /**
     * Order Update CLI
     */
    
    declare(strict_types = 1);
    
    namespace SomeVendor\SomeModule\Console\Command;
    
    use Magento\Framework\Api\SearchCriteriaBuilder;
    use Magento\Sales\Api\Data\OrderInterface;
    use Magento\Sales\Api\OrderRepositoryInterface;
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    /**
     * Order Update CLI
     */
    class OrderUpdate extends Command
    {
        /** @var OrderRepositoryInterface */
        protected $orderRepository;
    
        /** @var SearchCriteriaBuilder */
        protected $searchCriteriaBuilder;
    
        /**
         * OrderUpdate constructor.
         *
         * @param OrderRepositoryInterface $orderRepository
         * @param SearchCriteriaBuilder $searchCriteriaBuilder
         */
        public function __construct(
            OrderRepositoryInterface $orderRepository,
            SearchCriteriaBuilder $searchCriteriaBuilder
        ) {
            $this->orderRepository = $orderRepository;
            $this->searchCriteriaBuilder = $searchCriteriaBuilder;
            parent::__construct();
        }
    
        /**
         * @inheritDoc
         */
        protected function configure()
        {
            $this->setName('order:update');
            $this->setDescription('Order Update');
    
            parent::configure();
        }
    
        /**
         * @inheritDoc
         */
        protected function execute(InputInterface $input, OutputInterface $output)
        {
            foreach (['001', '002'] as $orderId) {
                echo 'Searching for order #' . $orderId . ' ... ';
                $order = $this->searchOrder($orderId, 1);
                echo $order ? ' Found' : ' Not Found';
                echo PHP_EOL;
            }
        }
    
        /**
         * Search Order
         *
         * @param string $incrementId
         * @param int $storeId
         *
         * @return OrderInterface|null
         */
        protected function searchOrder(string $incrementId, int $storeId): ?OrderInterface
        {
            $searchCriteria = $this->searchCriteriaBuilder
                ->addFilter('increment_id', $incrementId)
                ->addFilter('store.group_id', $storeId)
                ->create();
            $orders = $this->orderRepository->getList($searchCriteria)->getItems();
    
            return current($orders) ?: null;
        }
    }
  2. Run the following CLI commands:

    php bin/magento module:enable SomeVendor_SomeModule
    php bin/magento setup:upgrade
    php bin/magento cache:clean
    php bin/magento order:update

Expected result (*)

Searching for order #001 ... Not Found
Searching for order #002 ... Not Found

Actual result (*)

Searching for order #001 ...  Not Found
Searching for order #002 ... 
In Mysql.php line 110:
                                                                                                                                                                            
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'store.group_id' in 'where clause', query was: SELECT `main_table`.* FROM `sales_order` AS `main_table` WHERE ((`  
  increment_id` = '002')) AND ((`store`.`group_id` = 1))                                                                                                                    
                                                                                                                                                                            

In Mysql.php line 91:
                                                                                             
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'store.group_id' in 'where clause'  
                                                                                             

order:update

More Details

In the second foreach iteration the JoinProcessor it not applied because it is marked as already applied in the $this->appliedFields property of the Magento\Framework\Api\SearchCriteria\CollectionProcessor\JoinProcessor class. It looks right, but in the second iteration we have a fresh new instance of the order collection where is no JOIN which was added in the first iteration. You may check it with the

echo 'Collection ID: ' . spl_object_id($collection) . PHP_EOL;

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

m2-assistant bot commented Mar 30, 2020

Hi @yutv. 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.

@yutv do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Mar 30, 2020
@ghost ghost added this to Ready for QA in Community Backlog Mar 30, 2020
@sidolov sidolov added this to Ready for Grooming in Low Priority Backlog Sep 24, 2020
@sidolov sidolov added this to Ready for Confirmation in Issue Confirmation and Triage Board Oct 21, 2020
@ghost ghost removed this from Ready for QA in Community Backlog Oct 21, 2020
@ghost ghost removed this from Ready for Grooming in Low Priority Backlog Oct 21, 2020
@ghost ghost added Issue: ready for confirmation and removed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed labels Oct 21, 2020
@magento-engcom-team magento-engcom-team added the Reported on 2.4.0 Indicates original Magento version for the Issue report. label Nov 13, 2020
@stale
Copy link

stale bot commented Jan 28, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

@stale stale bot added the stale issue label Jan 28, 2021
@yutv
Copy link
Author

yutv commented Jan 28, 2021

I confirm the issue can be reproduced on vanilla Magento:

  • 2.4-develop branch
  • recent commit 2a4641b by Wed Jan 27 19:09:48 2021 -0600
    image

@stale stale bot removed the stale issue label Jan 28, 2021
@stale
Copy link

stale bot commented Apr 15, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

@stale stale bot added the stale issue label Apr 15, 2021
@yutv
Copy link
Author

yutv commented Apr 15, 2021

The issue still exists in vanilla Magento (commit d2155b3 by Thu Apr 15 16:17:07 2021 +0300, 2.4-develop branch).

See the screenshot.

image

Do I really need to confirm it exists each three months?

@m2-assistant
Copy link

m2-assistant bot commented Jun 8, 2021

Hi @engcom-Bravo. 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.

@m2-assistant
Copy link

m2-assistant bot commented Jun 9, 2021

Hi @engcom-Lima. 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-Lima engcom-Lima added the Issue: needs update Additional information is require, waiting for response label Jun 9, 2021
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Needs Update in Issue Confirmation and Triage Board Jun 9, 2021
@engcom-Delta
Copy link
Contributor

Hi @yutv,
There has no update on this issue. Hence closing it. Kindly raise new ticket if required.

@yutv
Copy link
Author

yutv commented Jun 24, 2021

Hi @yutv,
There has no update on this issue. Hence closing it. Kindly raise new ticket if required.

What updates are you talking about? I have confirmed the issue exists multiple times since it was created. The issue is clearly described step by step, so even a child can reproduce. I have not seen any adequate comment from Magento Staff since then but only a desire to close the issue. If I create a new Issue the situation will be the same. So why do I need waste my time?

@mikalaiprudnikau
Copy link

I can confirm it is still reproducible. Please take action.

@Rane2k
Copy link

Rane2k commented Mar 18, 2023

I can confirm a similar issue still exists when using \Magento\Tax\Model\TaxRuleRepository::getList

On the first call, the function works just fine, on the second call the joinProcessor does not add the JOIN to the SQL statement anymore.

@fgerodez
Copy link

fgerodez commented May 26, 2023

You can fix the problem by applying a patch to Api/SearchCriteria/CollectionProcessor/JoinProcessor.php to clear the cache at the end of the process function :

image

The problem is caused by the appliedFields property not getting cleared properly at the end and being reused for other completely unrelated collections.

fgerodez added a commit to fgerodez/magento2 that referenced this issue May 27, 2023
@fgerodez fgerodez linked a pull request May 27, 2023 that will close this issue
5 tasks
@andrewbess
Copy link
Contributor

Looks like we have a fix

@andrewbess andrewbess reopened this Mar 22, 2024
@m2-community-project m2-community-project bot removed the Issue: needs update Additional information is require, waiting for response label Mar 22, 2024
@m2-community-project m2-community-project bot added this to Ready for Confirmation in Issue Confirmation and Triage Board Mar 22, 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 Mar 25, 2024
@engcom-November engcom-November self-assigned this Mar 26, 2024
Copy link

m2-assistant bot commented Mar 26, 2024

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

  • 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-November
Copy link

Hello @yutv,

Thank you for the report and collaboration!

Verified this issue on 2.4-develop.
Followed the steps to reproduce and ran the console command, we are able to get the actual result.

Please take a look at the screenshot below:
image

Hence confirming the issue.

Please find the custom module used to reproduce the issue.
SomeVendor.zip

Thank you.

@engcom-November engcom-November added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Component: Cache Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Reported on 2.4.x Indicates original Magento version for the Issue report. Area: Order labels Mar 26, 2024
@m2-community-project m2-community-project bot moved this from Ready for Confirmation to Confirmed in Issue Confirmation and Triage Board Mar 26, 2024
@github-jira-sync-bot
Copy link

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

Copy link

m2-assistant bot commented Mar 26, 2024

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

@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Mar 26, 2024
@m2-community-project m2-community-project bot added this to Pull Request In Progress in High Priority Backlog Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Order Component: Cache 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. Reported on 2.4.0 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
High Priority Backlog
  
Pull Request In Progress
Development

Successfully merging a pull request may close this issue.