fix(products): cleared Variant Position resolves to file order, not NULL
A blank Variant Position cell previewed position->null and aborted the confirm transaction (variant.position is NOT NULL). Resolve the clear to the variant's file order at diff time so preview and apply stay in lockstep; carry file_order on VariantPlan instead of an identity-keyed map; release the read snapshot before PreviewStale/NothingToApply. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -107,9 +107,13 @@ def confirm_draft(conn: psycopg.Connection, storefront_id: int, account_id: int,
|
||||
catalog = repo.load_catalog(conn, storefront_id)
|
||||
diff_result = diff.compute_diff(catalog, products)
|
||||
if diff_result.fingerprint != row["fingerprint"]:
|
||||
# Release the read snapshot; nothing written.
|
||||
conn.rollback()
|
||||
raise PreviewStale()
|
||||
summary_counts = diff_result.summary
|
||||
if summary_counts["adds"] + summary_counts["updates"] == 0:
|
||||
# Release the read snapshot; nothing written.
|
||||
conn.rollback()
|
||||
raise NothingToApply()
|
||||
error_rows = [
|
||||
error.as_json()
|
||||
@@ -179,12 +183,12 @@ def _apply_product_plan(conn: psycopg.Connection, storefront_id: int,
|
||||
else:
|
||||
repo.update_image(conn, image_plan.image_id, image_plan.changes)
|
||||
|
||||
# File order within the product, for variant adds without an explicit position.
|
||||
file_positions = {id(v): i for i, v in enumerate(plan.canonical.variants, start=1)}
|
||||
for variant_plan in plan.variant_plans:
|
||||
if variant_plan.kind == "add":
|
||||
fields = diff.resolved_fields(variant_plan.canonical.fields)
|
||||
position = fields.get("position") or file_positions[id(variant_plan.canonical)]
|
||||
fields = diff.resolved_variant_fields(variant_plan.canonical, variant_plan.file_order)
|
||||
# diff time resolved any cleared position to file order; the
|
||||
# file_order fallback covers an absent position column.
|
||||
position = fields.get("position") or variant_plan.file_order
|
||||
url = fields.get("variant_image")
|
||||
image_id = image_ids[url] if url else None
|
||||
repo.insert_variant(
|
||||
|
||||
Reference in New Issue
Block a user