magento2: "Column not found" SQL error when saving a rule that references `sku` in its conditions

Preconditions

  1. Magento 2.3.0
  2. Ubuntu 18.04.1 LTS
  3. PHP 7.2.10
  4. MySQL 14.14 Distrib 5.7.25
  5. Static eav_attribute 74 (sku) is set to Store scope

Steps to reproduce

  1. Log into Magento Admin
  2. Navigate to MARKETING > Promotions > Catalog Price Rule
  3. Click the Add New Rule button
  4. Create and save a new rule referencing SKU under Conditions

Expected result

good

Actual result

bad

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)

Most upvoted comments

@nathancasebolt Yes on fresh install 2.3 sku is set to scope global