mirasvit / module-blog

Magento 2 Blog Extension
https://mirasvit.com/magento-2-extensions/blog.html
Open Software License 3.0
67 stars 48 forks source link

Ambiguous column user_id accesing with website limited role #160

Closed on4beinat closed 4 years ago

on4beinat commented 4 years ago

We have a Magento Commerce with User Roles limited to some websites and when we access to the posts section, we see this error:

exception(s):
Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'user_id' in where clause is ambiguous, query was: SELECT main_table.*, detail_role.role_name FROM admin_user AS main_table
 LEFT JOIN authorization_role AS user_role ON main_table.user_id = user_role.user_id AND user_role.parent_id != 0
 LEFT JOIN authorization_role AS detail_role ON user_role.parent_id = detail_role.role_id WHERE (user_id NOT IN('1', '2', '3', '4', '7'))
Exception #1 (PDOException): SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'user_id' in where clause is ambiguous

Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'user_id' in where clause is ambiguous, query was: SELECT main_table.*, detail_role.role_name FROM admin_user AS main_table
 LEFT JOIN authorization_role AS user_role ON main_table.user_id = user_role.user_id AND user_role.parent_id != 0
 LEFT JOIN authorization_role AS detail_role ON user_role.parent_id = detail_role.role_id WHERE (user_id NOT IN('1', '2', '3', '4', '7'))
#1 Magento\Framework\DB\Statement\Pdo\Mysql->_execute() called at [vendor/magento/zendframework1/library/Zend/Db/Statement.php:303]
#2 Zend_Db_Statement->execute() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:480]
#3 Zend_Db_Adapter_Abstract->query() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php:238]
#4 Zend_Db_Adapter_Pdo_Abstract->query() called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:542]
#5 Magento\Framework\DB\Adapter\Pdo\Mysql->_query() called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:617]
#6 Magento\Framework\DB\Adapter\Pdo\Mysql->query() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:737]
#7 Zend_Db_Adapter_Abstract->fetchAll() called at [vendor/magento/framework/Data/Collection/Db/FetchStrategy/Query.php:21]
#8 Magento\Framework\Data\Collection\Db\FetchStrategy\Query->fetchAll() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:778]
#9 Magento\Framework\Data\Collection\AbstractDb->_fetchAll() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:673]
#10 Magento\Framework\Data\Collection\AbstractDb->getData() called at [generated/code/Magento/User/Model/ResourceModel/User/Collection/Interceptor.php:453]
#11 Magento\User\Model\ResourceModel\User\Collection\Interceptor->getData() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:576]
#12 Magento\Framework\Data\Collection\AbstractDb->loadWithFilter() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#13 Magento\User\Model\ResourceModel\User\Collection\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#14 Magento\User\Model\ResourceModel\User\Collection\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#15 Magento\User\Model\ResourceModel\User\Collection\Interceptor->___callPlugins() called at [generated/code/Magento/User/Model/ResourceModel/User/Collection/Interceptor.php:429]
#16 Magento\User\Model\ResourceModel\User\Collection\Interceptor->loadWithFilter() called at [vendor/magento/framework/Data/Collection/AbstractDb.php:561]
#17 Magento\Framework\Data\Collection\AbstractDb->load() called at [generated/code/Magento/User/Model/ResourceModel/User/Collection/Interceptor.php:414]
#18 Magento\User\Model\ResourceModel\User\Collection\Interceptor->load() called at [vendor/magento/framework/Data/Collection.php:838]
#19 Magento\Framework\Data\Collection->getIterator() called at [generated/code/Magento/User/Model/ResourceModel/User/Collection/Interceptor.php:908]
#20 Magento\User\Model\ResourceModel\User\Collection\Interceptor->getIterator() called at [vendor/mirasvit/module-blog/Model/Post/Attribute/Source/Author.php:33]
#21 Mirasvit\Blog\Model\Post\Attribute\Source\Author->getOptionArray() called at [vendor/mirasvit/module-blog/Model/Post/Attribute/Source/Author.php:49]
#22 Mirasvit\Blog\Model\Post\Attribute\Source\Author->getAllOptions() called at [vendor/magento/module-eav/Model/Entity/Attribute/Source/AbstractSource.php:168]

I'm going to be working on this issue so, if I find a fix for this I will post it ASAP.

on4beinat commented 4 years ago

It looks like it may be a Magento Bug.

on4beinat commented 4 years ago

Ok, It was a Magento Bug. If anyone finds this issue, you can quick fix it by overriding the limitAdminPermissionUsers() function in Magento\AdminGws\Model\Collections There replace:

$collection->addFieldToFilter('user_id', ['nin' => $limited]);

With:

$collection->addFieldToFilter('main_table.user_id', ['nin' => $limited]);