After updating Magento from 2.1.6 to 2.3.2 and PHP from 5.6.30 to 7.2.20, now running into errors on page load.

Have a module called Inquiry, which consists of forms to request things, and there is a custom table called 'inquiry_requests' that contains the things that can be requested.

Before the update, everything worked fine, but after updating getting the following error on page load for one of the forms when I run it in Developer mode. Tried clearing cache, deleting the generated folder, rerunning setup di compile multiple times, but the error continues to persist.

So it appears that it's occurring when we query for the custom table's data through the collection.

Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Component\Inquiry\Model\Resource\Requests\Collection\Interceptor
#1 Magento\Framework\ObjectManager\Factory\Compiled->create('Component\Inq...', array()) called at [vendor/magento/framework/ObjectManager/ObjectManager.php:56]
#2 Magento\Framework\ObjectManager\ObjectManager->create('\Component\In...', array()) called at [generated/code/Component/Inquiry/Model/Resource/Requests/CollectionFactory.php:43]
#3 Component\Inquiry\Model\Resource\Requests\CollectionFactory->create() called at [app/code/Component/Inquiry/Helper/Requests.php:25]
#4 Component\Inquiry\Helper\Requests->getRequestsItems(array('...')) called at [app/code/Component/Inquiry/view/frontend/templates/form/requests.phtml:104]
report.CRITICAL: Type Error occurred when creating object: Component\Inquiry\Model\Resource\Requests\Collection\Interceptor, Argument 5 passed to Component\Inquiry\Model\Resource\Requests\Collection\Interceptor::__construct() must implement interface Magento\Framework\DB\Adapter\AdapterInterface or be null, string given, called in /var/www/vhosts/MyWebsite/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 116 [] []
report.ERROR: Type Error occurred when creating object: Component\Inquiry\Model\Resource\Requests\Collection\Interceptor [] []

namespace Component\Inquiry\Model\Resource\Requests;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;

class Collection extends AbstractCollection
     * Define model & resource model
    protected function _construct()
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="Component\Inquiry\Model\Resource\Requests\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
            <argument name="mainTable" xsi:type="string">inquiry_requests</argument>
            <argument name="resourceModel" xsi:type="string">Component\Inquiry\Model\Resource\Requests</argument>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
            <argument name="collections" xsi:type="array">
                <item name="requests_list_data_source" xsi:type="string">Component\Inquiry\Model\Resource\Requests\Collection</item>

Component\Inquiry\Model\Resource\Requests\Collection is the namespace of your collection for your resource models, it already exists, "overriding" it or creating a virtual type with the namespace won't do much.

What you want to do in this specific case, where you are using a virtual type to pass to Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory, is add ...\Grid\Collection to the namespace.


What you can do now is use this virtual type and pass it as you're doing right now to Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory using the collections argument.

Cache flush and you should be good to go.

| improve this answer | |
  • Thank you for that!!!!! – logic4life Mar 17 at 21:09
  • Incredibly helpful! This fixed a problem I was having. Thanks! – seanbreeden Aug 14 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.