-
Notifications
You must be signed in to change notification settings - Fork 174
Description
What happened?
Description
With the following setup:
craftcms/cms: 5.8.19craftcms/commerce: 5.4.9craftcms/feed-me: 6.11.0
The queue job “Generating catalog pricing data” fails with:
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'sitestores'
The generated subquery contains the same LEFT JOINs twice with the same aliases (sitestores and purchasables_stores), which triggers the error.
Representative excerpt (trimmed for brevity):
SELECT `elements`.`id`
FROM (
SELECT ...
FROM `elements` `elements`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id`
LEFT JOIN `commerce_site_stores` `sitestores` ON `elements_sites`.`siteId` = `sitestores`.`siteId`
LEFT JOIN `commerce_purchasables_stores` `purchasables_stores`
ON `purchasables_stores`.`storeId` = `sitestores`.`storeId`
AND `purchasables_stores`.`purchasableId` = `elements`.`id`
-- duplicated joins with identical aliases below
LEFT JOIN `commerce_site_stores` `sitestores` ON `elements_sites`.`siteId` = `sitestores`.`siteId`
LEFT JOIN `commerce_purchasables_stores` `purchasables_stores`
ON `purchasables_stores`.`storeId` = `sitestores`.`storeId`
AND `purchasables_stores`.`purchasableId` = `elements`.`id`
WHERE (`purchasables_stores`.`promotable` = TRUE) AND ...
) `subquery`Steps to reproduce
-
Install Craft CMS 5.8.19, Craft Commerce 5.4.9, and Feed Me 6.11.0.
-
Use a multi-site setup with at least one Store and its Site Stores; have standard purchasables (variants).
-
Trigger pricing catalog generation:
- via queue (e.g., after a Feed Me import or product changes), or
- via CLI:
php craft commerce/pricing-catalog/generate
-
Observe the job failure with SQL 1066.
Expected behavior
The “Generating catalog pricing data” job completes successfully and does not add duplicate JOINs/aliases.
Actual behavior
The job fails with:
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'sitestores'
Inspection of the SQL shows two identical LEFT JOINs to commerce_site_stores and commerce_purchasables_stores using the same aliases (sitestores, purchasables_stores).
Craft CMS version
5.8.19
Craft Commerce version
5.4.9
PHP version
8.2.23
Operating system and version
No response
Database type and version
MySQL 8.0.43
Image driver and version
No response