mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-22 02:40:02 +00:00
fix(controllers): make update_variant_attribute_values Postgres-valid (drop UPDATE..JOIN)
update_variant_attribute_values (propagates renamed Item Attribute Values to variant items) used a qb UPDATE ... JOIN. Postgres has no UPDATE..JOIN syntax, so renaming an Item Attribute Value errored on Postgres. Rewrite as a correlated UPDATE that restricts to variant items via a subquery on the parent (item_variant_table.parent.isin(variant Items)) instead of joining the Item table. MariaDB behaviour is unchanged. Covered by the existing test_item.test_rename_attribute_value_updates_variants and test_swapped_attribute_value_renames_update_variants, which errored on Postgres before and now pass on both engines. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -169,13 +169,17 @@ def update_variant_attribute_values(item_attribute):
|
||||
for old_value, new_value in value_map.items():
|
||||
attribute_value_case = attribute_value_case.when(attribute_value == old_value, new_value)
|
||||
|
||||
(
|
||||
frappe.qb.update(item_variant_table)
|
||||
.join(item_table)
|
||||
.on(item_table.name == item_variant_table.parent)
|
||||
.set(attribute_value, attribute_value_case.else_(attribute_value))
|
||||
# Postgres has no UPDATE ... JOIN; restrict to variant items via a subquery on the parent instead.
|
||||
variant_items = (
|
||||
frappe.qb.from_(item_table)
|
||||
.select(item_table.name)
|
||||
.where(item_table.variant_of.isnotnull())
|
||||
.where(item_table.variant_of != "")
|
||||
)
|
||||
(
|
||||
frappe.qb.update(item_variant_table)
|
||||
.set(attribute_value, attribute_value_case.else_(attribute_value))
|
||||
.where(item_variant_table.parent.isin(variant_items))
|
||||
.where(item_variant_table.attribute == item_attribute.name)
|
||||
.where(attribute_value.isin(list(value_map)))
|
||||
).run()
|
||||
|
||||
Reference in New Issue
Block a user