magento2: "Column not found" SQL error when saving a rule that references `sku` in its conditions
Preconditions
- Magento 2.3.0
- Ubuntu 18.04.1 LTS
- PHP 7.2.10
- MySQL 14.14 Distrib 5.7.25
- Static eav_attribute 74 (
sku) is set to Store scope
Steps to reproduce
- Log into Magento Admin
- Navigate to MARKETING > Promotions > Catalog Price Rule
- Click the Add New Rule button
- Create and save a new rule referencing SKU under Conditions
Expected result

Actual result

Database log:
[2019-02-05 14:42:24] main.CRITICAL: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'cpa.store_id' in 'field list', query was: SELECT cpe.entity_id, cpa.store_id, cpa.valueFROMcatalog_product_entityAScpeINNER JOINcatalog_product_entityAScpa ON cpe.entity_id = cpa.entity_id WHERE (attribute_id = 74)
Possible Pain Points
Here’s what I think is going on, starting here:
\Magento\Rule\Model\Condition\Product\AbstractProduct.php:353
if ('category_ids' != $attribute) {
// stuff
if ($this->getAttributeObject()->isScopeGlobal()) {
// stuff
} else {
$this->_entityAttributeValues = $productCollection->getAllAttributeValues($attribute);
}
}
Since sku has a Store scope rather than Global, we take the else path, eventually winding up at the getAllAttributeValues function in \Magento\Catalog\Model\ResourceModel\Product\Collection:1048. Once we get here, because sku has a static backend_type with no other associated attribute table, Magento joins the catalog_product_entity table to itself, looks for store_id (which doesn’t exist in that table), and crashes.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (11 by maintainers)
@nathancasebolt Yes on fresh install 2.3 sku is set to scope global