Question

Error when running indexing:

Notice: Undefined index: queries in /var/www/stage/vendor/magento/module-catalog-graph-ql/Plugin/Search/Request/ConfigReader.php on line 84
Was it helpful?

Solution

I found that the root of the issue here is that a 3rd party module we installed had a bug in it that was preventing the indexer from finding product attributes.

The module was the MagePlaza Admin Permissions for Magento 2 module v1.0.0 They suggested I update to v1.0.1 and that resolved the issue.


In file vendor/mageplaza/module-admin-permissions/Plugin/Catalog/Model/ResourceModel/Product/Attribute/Collection.php, function beforeLoad() the indexer gets into this bit of code:

//hide all grid columns when user haven't permission to view product
if (!$this->helperData->isAllow('Mageplaza_AdminPermissions::product_attribute_view')) {
    $collection->getSelect()->where('0=1');

    return [$printQuery, $logQuery];
}

Adding that where condition tells the indexer that there aren’t any product attributes to use in the indexing process and throws the error.


One thing I learned in debugging this is how a product collection works a bit more... In vendor/magento/module-catalog-graph-ql/Plugin/Search/Request/ConfigReader.php I was analyzing the query that it is putting out where the error occurs using $productAttributes->getSelect()->__toString(). When I ran that query manually I would get 133 attributes.

The next line down calls foreach ($productAttributes->getItems() as $attribute) { and would not get into the for loop. How could I go from 133 to 0???

What I learned is that calling getItems() on a collection calls the load() function. This allows other observers to modify the query. In this case, the MagePlaza module was modifying the query via an observer.

So one debugging method that I learned here when trying to analyze the query a collection is using is to call the load() method before dumping out the query.

$collection->load();
$collection->getSelect()->__toString();

NOTE: technically you don't need ->__toString() as calling just $collection->getSelect() should work, but to me I'm used to calling the __toString() method from M1.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top