magento2: Invalid argument supplied for foreach() in vendor/magento/module-catalog/Model/Category/DataProvider.php on line 398

Preconditions (*)

  1. Magento v 2.3.6
  2. PHP version 7.2.30
  3. Hosting Provider: Nexcess

we have multistore setup

Steps to reproduce (*)

  1. Upgrade the Magento version from 2.3.1 to 2.3.6
  2. After upgrading the version go to admin and open the Category page. (Catalog -> Categories)

Expected result (*)

  1. Should be able to view all the categories in the admin

Actual result (*)

  1. Saw below error on category page in the admin

` 1 exception(s): Exception #0 (Exception): Warning: Invalid argument supplied for foreach() in vendor/magento/module-catalog/Model/Category/DataProvider.php on line 398

#1 Magento\Catalog\Model\Category\DataProvider->getAttributesMeta() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#2 Magento\Catalog\Model\Category\DataProvider\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#3 Magento\Catalog\Model\Category\DataProvider\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#4 Magento\Catalog\Model\Category\DataProvider\Interceptor->___callPlugins() called at [generated/code/Magento/Catalog/Model/Category/DataProvider/Interceptor.php:65]
#5 Magento\Catalog\Model\Category\DataProvider\Interceptor->getAttributesMeta() called at [vendor/magento/module-catalog/Model/Category/DataProvider.php:299]
#6 Magento\Catalog\Model\Category\DataProvider->prepareMeta() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#7 Magento\Catalog\Model\Category\DataProvider\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#8 Magento\Catalog\Model\Category\DataProvider\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#9 Magento\Catalog\Model\Category\DataProvider\Interceptor->___callPlugins() called at [generated/code/Magento/Catalog/Model/Category/DataProvider/Interceptor.php:39]
#10 Magento\Catalog\Model\Category\DataProvider\Interceptor->prepareMeta() called at [vendor/magento/module-catalog/Model/Category/DataProvider.php:231]
#11 Magento\Catalog\Model\Category\DataProvider->getMeta() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#12 Magento\Catalog\Model\Category\DataProvider\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#13 Magento\Catalog\Model\Category\DataProvider\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#14 Magento\Catalog\Model\Category\DataProvider\Interceptor->___callPlugins() called at [generated/code/Magento/Catalog/Model/Category/DataProvider/Interceptor.php:26]
#15 Magento\Catalog\Model\Category\DataProvider\Interceptor->getMeta() called at [vendor/magento/framework/View/Element/UiComponentFactory.php:318]
#16 Magento\Framework\View\Element\UiComponentFactory->mergeMetadata() called at [vendor/magento/framework/View/Element/UiComponentFactory.php:218]
#17 Magento\Framework\View\Element\UiComponentFactory->create() called at [vendor/magento/framework/View/Layout/Generator/UiComponent.php:140]
#18 Magento\Framework\View\Layout\Generator\UiComponent->generateComponent() called at [vendor/magento/framework/View/Layout/Generator/UiComponent.php:103]
#19 Magento\Framework\View\Layout\Generator\UiComponent->process() called at [vendor/magento/framework/View/Layout/GeneratorPool.php:81]
#20 Magento\Framework\View\Layout\GeneratorPool->process() called at [vendor/magento/framework/View/Layout.php:352]
#21 Magento\Framework\View\Layout->generateElements() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:89]
#22 Magento\Framework\View\Layout\Interceptor->generateElements() called at [vendor/magento/framework/View/Layout/Builder.php:129]
#23 Magento\Framework\View\Layout\Builder->generateLayoutBlocks() called at [vendor/magento/framework/View/Page/Builder.php:55]
#24 Magento\Framework\View\Page\Builder->generateLayoutBlocks() called at [vendor/magento/framework/View/Layout/Builder.php:65]
#25 Magento\Framework\View\Layout\Builder->build() called at [vendor/magento/framework/View/Layout.php:259]
#26 Magento\Framework\View\Layout->build() called at [vendor/magento/framework/View/Layout.php:884]
#27 Magento\Framework\View\Layout->getBlock() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:414]
#28 Magento\Framework\View\Layout\Interceptor->getBlock() called at [vendor/magento/module-backend/Model/View/Result/Page.php:26]
#29 Magento\Backend\Model\View\Result\Page->setActiveMenu() called at [generated/code/Magento/Backend/Model/View/Result/Page/Interceptor.php:24]
#30 Magento\Backend\Model\View\Result\Page\Interceptor->setActiveMenu() called at [vendor/magento/module-catalog/Controller/Adminhtml/Category/Edit.php:113]
#31 Magento\Catalog\Controller\Adminhtml\Category\Edit->execute() called at [generated/code/Magento/Catalog/Controller/Adminhtml/Category/Edit/Interceptor.php:24]
#32 Magento\Catalog\Controller\Adminhtml\Category\Edit\Interceptor->execute() called at [vendor/magento/framework/App/Action/Action.php:108]
#33 Magento\Framework\App\Action\Action->dispatch() called at [vendor/magento/module-backend/App/AbstractAction.php:248]
#34 Magento\Backend\App\AbstractAction->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#35 Magento\Catalog\Controller\Adminhtml\Category\Edit\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#36 Magento\Catalog\Controller\Adminhtml\Category\Edit\Interceptor->Magento\Framework\Interception\{closure}() called at [app/code/WeltPixel/Backend/Plugin/Utility.php:76]
#37 WeltPixel\Backend\Plugin\Utility->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#38 Magento\Catalog\Controller\Adminhtml\Category\Edit\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-backend/App/Action/Plugin/Authentication.php:143]
#39 Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#40 Magento\Catalog\Controller\Adminhtml\Category\Edit\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#41 Magento\Catalog\Controller\Adminhtml\Category\Edit\Interceptor->___callPlugins() called at [generated/code/Magento/Catalog/Controller/Adminhtml/Category/Edit/Interceptor.php:39]
#42 Magento\Catalog\Controller\Adminhtml\Category\Edit\Interceptor->dispatch() called at [vendor/magento/framework/App/FrontController.php:186]
#43 Magento\Framework\App\FrontController->processRequest() called at [vendor/magento/framework/App/FrontController.php:119]
#44 Magento\Framework\App\FrontController->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#45 Magento\Framework\App\FrontController\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#46 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#47 Magento\Framework\App\FrontController\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/App/FrontController/Interceptor.php:26]
#48 Magento\Framework\App\FrontController\Interceptor->dispatch() called at [vendor/magento/framework/App/Http.php:116]
#49 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:24]
#50 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:261]
#51 Magento\Framework\App\Bootstrap->run() called at [index.php:39]
`
  1. Noticed the same error in var/log/system.log and var/log/debug.log files

We didn’t face any issues during the version upgrade. Could this be a PHP version issue? I think the Magento 2.3.6 should work on PHP 7.2, right? Tried to find the solution on StackOverflow but didn’t any specific solution or even a workaround.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

I’m almost certain this is happening when:

  • A third party module in app/code has an install/upgrade script.
  • The module adds an attribute to a category that provides a list of options, thus uses a custom Source model
  • Upon first setup:upgrade on a fresh upgrade on Magento; these options are not present, hence the error

Both me and OP had third party modules, this I’m sure can’t be replicated from a fresh install & upgrade.