magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

Custom admin UI component grid breaks when collection is not AbstractDb #32292

Open zaximus84 opened 3 years ago

zaximus84 commented 3 years ago

Preconditions (*)

  1. Install Magento 2.4.2
  2. Build a custom admin grid using UI components and a data provider.
  3. Use a collection for your data provider that extends Magento\Framework\Data\Collection, but not Magento\Framework\Data\Collection\AbstractDb.

Steps to reproduce (*)

  1. Attempt to view the grid in admin.

Expected result (*)

  1. The grid displays without error.

Actual result (*)

  1. This error occurs: Call to undefined method {custom collection class}::getSelect() Exception in /var/www/html/vendor/magento/framework/View/Element/UiComponent/DataProvider/FilterPool.php:45

This issue was introduced in 2.4.2 due to changes in the FilterPool class. See this commit: https://github.com/magento/magento2/commit/2638e0ffae57f351c512e47a0295d4c2d376681a

The applyFilters method type hints that the $collection argument can be an instance of Magento\Framework\Data\Collection or Magento\Framework\Data\Collection\AbstractDb, but the method executes operations that are only guaranteed on AbstractDb (i.e. getSelect).

Any AbstractDb operations should only be executed after some sort of type check to prevent errors for collections that don't extend that abstract. As an example, I built an admin grid that populates data from a remote API and has no need of a database select object, so it doesn't extend AbstractDb.


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 3 years ago

Hi @zaximus84. Thank you for your report. To help us process this issue please make sure that you provided the following information:

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.

Please, add a comment to assign the issue: @magento I am working on this


: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, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

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

hostep commented 3 years ago

The exact same problem was discovered in https://github.com/baldwin-agency/magento2-module-url-data-integrity-checker/issues/16

If you wrap that contents of that applyFilters method in something like the following, it no longer crashes, but I have no idea if that would be considered a good solution:

public function applyFilters(Collection $collection, SearchCriteriaInterface $criteria)
{
    if (method_exists($collection, 'getSelect')) {
        ...
    }
}

But the type checking on AbstractDb could be a solution as well...

@engcom-Golf: what do you think might be a good solution here?

myAlexT commented 3 years ago

Hello. Faced this issue when going to Report->Braintree Settlement grid. And I can reproduce this problem on a clean Magento 2.4.2 installation!

stale[bot] commented 3 years ago

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!

hostep commented 3 years ago

Issue is definitely not stale, leaving a comment to not close it.

@Den4ik: can we get somebody to review this and propose a solution? I'm willing to create a PR for this if a good solution can be proposed, thanks!

We needed to add a silly workaround to keep our module working on 2.4.2 because of this bug: https://github.com/baldwin-agency/magento2-module-url-data-integrity-checker/pull/17/files

m2-assistant[bot] commented 3 years ago

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

myAlexT commented 3 years ago

image I confirm that the error is still valid. All magento 2.4.2 stores have this bug when going to Report->Braintree Settlement grid.

engcom-Echo commented 3 years ago

Hi @zaximus84 ,

On step 3 , Can you please specify which collection you used for the data provider.

Thanks

hostep commented 3 years ago

Hi @engcom-Echo

If you need an easy way to reproduce: install version 1.2.0 of this open source module on Magento 2.4.1. Then in the backoffice of Magento, go to Catalog > Data Integrity Checker and click on one of the 4 submenu's and notice that the page doesn't crash. Now do the same on Magento 2.4.2 and notice that those pages now suddenly start crashing.

The problem is triggered from a custom collection that is used by a grid datasource and inherits from Magento\Framework\Data\Collection.

The change in https://github.com/magento/magento2/commit/2638e0ffae57f351c512e47a0295d4c2d376681a#diff-589c211efb97038b69ed19a3bbfa83af013eacf4c8f218cb8f3705aaef675543 to the applyFilters method introduced the problem in Magento 2.4.2. The new code assumes that $collection always has a getSelect method. But $collection can be either a Magento\Framework\Data\Collection\AbstractDb or a Magento\Framework\Data\Collection. For the AbstractDb, it indeed has a getSelect method, see here. But the Collection class - or its parents - does not have a getSelect method. So the code that was introduced in https://github.com/magento/magento2/commit/2638e0ffae57f351c512e47a0295d4c2d376681a#diff-589c211efb97038b69ed19a3bbfa83af013eacf4c8f218cb8f3705aaef675543 will crash for all instances of $collection that aren't an AbstractDb.

Hope this makes the problem even more clearer then it already was.

sumeshkumar577 commented 3 years ago

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

magento-deployment-service[bot] commented 3 years ago

Hi @sumeshkumar577. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 3 years ago

Hi @sumeshkumar577, here is your Magento Instance: https://be40c214bcd2354840529352e557ece0-2-4-develop.instances.magento-community.engineering Admin access: https://be40c214bcd2354840529352e557ece0-2-4-develop.instances.magento-community.engineering/admin_217a Login: 36258fb1 Password: cb405403b4f0

github-jira-sync-bot commented 3 years ago

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

m2-assistant[bot] commented 3 years ago

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

github-jira-sync-bot commented 3 years ago

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.magento.com/browse/AC-1013

github-jira-sync-bot commented 3 years ago

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.magento.com/browse/AC-1013