[object Object]

← back to Dw Five Field Step0

Idempotent hardening: skip add-sample/build-roll when product already has a Sample/Roll option1 (different sku) — converts ~439 create_422 errors into clean skips

dc27698203e742393120e0584d203c9985d9d0b7 · 2026-06-22 05:55:16 -0700 · Steve Abrams

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files touched

Diff

commit dc27698203e742393120e0584d203c9985d9d0b7
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon Jun 22 05:55:16 2026 -0700

    Idempotent hardening: skip add-sample/build-roll when product already has a Sample/Roll option1 (different sku) — converts ~439 create_422 errors into clean skips
    
    Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---
 bulk-fivefield-exec.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/bulk-fivefield-exec.py b/bulk-fivefield-exec.py
index b2c5493..a52f574 100644
--- a/bulk-fivefield-exec.py
+++ b/bulk-fivefield-exec.py
@@ -177,6 +177,7 @@ def process(item, results, dry_run=False):
              "option1": v.get("option1"), "inv_mgmt": v.get("inventory_management")}
             for v in variants]
         existing_skus = {(v.get("sku") or "") for v in variants}
+        existing_opts = {(v.get("option1") or "").strip().lower() for v in variants}
 
         if fix == "add-sample":
             target = f"{dw}-Sample"
@@ -186,6 +187,10 @@ def process(item, results, dry_run=False):
                 rec["status"] = "skipped"; rec["reason"] = "sample_variant_already_exists"
                 rec["after_variants"] = rec["before_variants"]
                 results.append(rec); print(f"SKIP {dw}: sample exists"); return 0
+            if "sample" in existing_opts:  # product already has a Sample option (different sku) -> 422 if we POST
+                rec["status"] = "skipped"; rec["reason"] = "sample_option_already_present"
+                rec["after_variants"] = rec["before_variants"]
+                results.append(rec); print(f"SKIP {dw}: sample option present"); return 0
             vbody = {"variant": {
                 "option1": "Sample", "sku": target, "price": price,
                 "inventory_management": None, "inventory_policy": "continue",
@@ -208,6 +213,10 @@ def process(item, results, dry_run=False):
                 rec["status"] = "skipped"; rec["reason"] = "roll_variant_already_exists"
                 rec["after_variants"] = rec["before_variants"]
                 results.append(rec); print(f"SKIP {dw}: roll exists"); return 0
+            if "roll" in existing_opts:   # product already has a Roll option (different sku) -> 422 if we POST
+                rec["status"] = "skipped"; rec["reason"] = "roll_option_already_present"
+                rec["after_variants"] = rec["before_variants"]
+                results.append(rec); print(f"SKIP {dw}: roll option present"); return 0
             vbody = {"variant": {
                 "option1": "Roll", "sku": target, "price": f"{map_price:.2f}",
                 "inventory_management": "shopify", "inventory_policy": "continue",

← 7ba3b7d auto-save: 2026-06-22T05:34:04 (1 files) — out/bulk-fivefiel  ·  back to Dw Five Field Step0  ·  auto-save: 2026-06-22T06:34:16 (1 files) — out/bulk-fivefiel 8c5a8c8 →