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:
2026-06-11 16:14:14 -07:00
parent 0c7865e9e1
commit a8538d3ecc
4 changed files with 77 additions and 14 deletions
+18
View File
@@ -113,6 +113,24 @@ def test_changed_variant_position_reports_honest_before():
assert {"field": "position", "before": 1, "after": 2} in ventry["changes"]
def test_blank_position_cell_resolves_to_file_order_unchanged():
# A present-but-empty Variant Position cell resets to file order (the spec's
# "defaults to file order"), never to NULL — here file order matches the
# catalog position, so nothing changes.
diff = compute_diff(_catalog_mug(), _canon(POSITION_HEADER, MUG_ROW + ","))
assert diff.records[0]["kind"] == "unchanged"
def test_blank_position_cell_updates_to_file_order():
catalog = _catalog_mug()
catalog["moon-mug"].variants[0].position = 2
diff = compute_diff(catalog, _canon(POSITION_HEADER, MUG_ROW + ","))
[rec] = diff.records
assert rec["kind"] == "update"
[ventry] = rec["detail"]["variants"]
assert {"field": "position", "before": 2, "after": 1} in ventry["changes"]
def test_error_product_classifies_error():
diff = compute_diff({}, _canon("Handle,Title,Variant Price", "mug,Mug,nope"))
[rec] = diff.records
+19
View File
@@ -150,6 +150,25 @@ def test_confirm_update_changes_only_diffed_fields(migrated_conn, merchant):
assert migrated_conn.execute("SELECT count(*) FROM product").fetchone()[0] == 2 # no dupes (BUC-3)
def test_confirm_blank_position_cell_round_trips(migrated_conn, merchant):
# A present-but-empty Variant Position cell resolves to file order at diff
# time — never SET position = NULL (which would abort the confirm on the
# NOT NULL constraint).
d1 = _validate(migrated_conn, merchant)
products.confirm_draft(migrated_conn, merchant["storefront_id"], merchant["account_id"], d1["id"])
blank_position_csv = (
b"Handle,Title,Vendor,Variant Price,Variant Position\n"
b"moon-mug,Moon Mug,Acme,21.00,\n"
b"star-tee,Star Tee,Acme,24.00,\n"
)
d2 = _validate(migrated_conn, merchant, blank_position_csv)
products.confirm_draft(migrated_conn, merchant["storefront_id"], merchant["account_id"], d2["id"])
price = migrated_conn.execute(
"SELECT v.price FROM variant v JOIN product p ON p.id = v.product_id WHERE p.handle='moon-mug'"
).fetchone()[0]
assert str(price) == "21.00"
def test_confirm_mixed_applies_valid_records_errors(migrated_conn, merchant):
draft = _validate(migrated_conn, merchant, MIXED_CSV)
run_id = products.confirm_draft(