api.scripts.shopify_catalog_reconciliation¶
Verification that Shopify reflects the sellable Airtable catalog.
The comparison itself is read-only; once it’s done, every discrepancy create/update_product can fix is queued for them automatically (see auto_fix) – the dashboard’s manual buttons still work the same.
This logic was developed and validated against real production data,
including two real matching bugs found and fixed along the way (see
“Airtable’s Variation.ShopifyID is not a variant id” below for one of
them).
Three checks, from broad to specific:
Every relevant Model exists as a Shopify product.
Every relevant Variation of a Model found in Shopify exists as a Shopify variant.
Every unit marked
Statut commercial = "A vendre"of a Variation flaggedto_sell_on_shopifymaps to a Shopify variant whose inventory quantity matches the count of such units. A unit can be “A vendre” (for sale) through a completely different channel – eBay, an auction, direct sale – without ever being meant for Shopify; only Shopify-bound stock is checked against Shopify. Units in an excluded condition (EXCLUDED_CONDITIONS: “Abimé”, “Très abimé”) are never put on Shopify by create/update_product, so they aren’t expected there either.
“Relevant” means to_sell_on_shopify and currently has at least one “A
vendre” unit – a Model/Variation that’s the kind of thing sold online but
has zero current stock is correctly absent from Shopify, not “missing”.
The reverse is checked too: a Model still on Shopify that isn’t
to_sell_on_shopify (shopify_products_not_a_vendre), and a variant
with Shopify stock but no “A vendre” unit behind it
(shopify_variants_not_a_vendre). Both raise an alert email and queue
update_product, which deletes the first and zeroes the second’s stock. A
to_sell_on_shopify Model with nothing “A vendre” stays listed at 0.
Airtable’s Variation.ShopifyID is not a variant id – confirmed against
production data, it always duplicates the parent Model’s product id, even
across Variations that are genuinely different Shopify variants. There is no
Airtable field holding a real Shopify variant id at all. Instead, a Shopify
variant is identified by its selectedOptions values (option names vary
per product type, so matching is name-agnostic), and those literal value
strings do match Airtable exactly: a Variation’s own Variant_value (e.g.
a size/range) plus a Unit’s Etat esthétique (condition) together pin down
one specific Shopify variant. One Airtable Variation therefore corresponds to
one Shopify variant per condition it has stock in, not a single variant.
Plus a documentation check on every relevant Model found in Shopify that has a “Documentation” PDF in Airtable (the source of truth): is its product’s “PDF Descriptif” metafield missing, or different from Airtable’s current attachment (per the companion source-id metafield – see api/scripts/_product_documentation.py)? And the to-do list upstream of that: every relevant Model – on Shopify yet or not – with no PDF in its Airtable “Documentation” field at all.
Plus a historical diff of Model/Variation ids against the previous run, so catalog growth over time is an explicit metric.
Attributes¶
Classes¶
Compares the Airtable sellable catalog against Shopify, then queues |
Functions¶
|
Prices at 0 (or empty/invalid) on stock meant to be sold: A vendre |
|
Everything that breaks "one Model = one Annonces Shopify = one Shopify |
|
|
|
Best-effort: add a |
|
Best-effort: for each entry in |
|
Best-effort: for each entry in |
|
Best-effort: for each Model in the missing/outdated documentation |
|
One email per run listing what's on Shopify but shouldn't be. |
|
Queues the same runs the dashboard's manual buttons do: |
Module Contents¶
- api.scripts.shopify_catalog_reconciliation.logger¶
- api.scripts.shopify_catalog_reconciliation.find_price_issues(shopify_units: list[api.domain.catalog.Unit], variations_by_id: dict[str, api.domain.catalog.Variation], products: list[api.integrations.shopify.catalog.ShopifyProduct], stocked_variant_ids: set[str]) dict[str, list[dict[str, Any]]]¶
Prices at 0 (or empty/invalid) on stock meant to be sold: A vendre units that create/update_product would refuse to list, and Shopify variants that Airtable has A vendre stock for (
stocked_variant_ids). A 0 € variant Airtable has no stock for is correct – the sales team zeroes the price when stock runs out – and archived products aren’t orderable at all.
- api.scripts.shopify_catalog_reconciliation.find_listing_issues(models: list[api.domain.catalog.Model], variations_by_id: dict[str, api.domain.catalog.Variation], units: list[api.domain.catalog.Unit], listings: list[api.domain.catalog.ShopifyListing], products: list[api.integrations.shopify.catalog.ShopifyProduct], dev_store_matches: dict[str, api.integrations.shopify.catalog.ShopifyProduct]) dict[str, list[dict[str, Any]]]¶
Everything that breaks “one Model = one Annonces Shopify = one Shopify product”: duplicates (e.g. a create that ran twice), Shopify products Airtable doesn’t know about, and units reaching several listings.
- api.scripts.shopify_catalog_reconciliation.build_result(models: list[api.domain.catalog.Model], variations: list[api.domain.catalog.Variation], units: list[api.domain.catalog.Unit], listings: list[api.domain.catalog.ShopifyListing], products: list[api.integrations.shopify.catalog.ShopifyProduct], previous_snapshot: dict[str, Any] | None) tuple[api.scripts.base.ScriptResult, dict[str, Any]]¶
- api.scripts.shopify_catalog_reconciliation.DOCUMENTATION_DETAIL_KEYS = ('documentation_missing_in_airtable', 'documentation_missing_in_shopify',...¶
- api.scripts.shopify_catalog_reconciliation.attach_airtable_urls(details: dict[str, Any]) None¶
Best-effort: add a
urlkey to every{id, name}entry indetails.Never raises –
record_urlalready degrades toNoneon failure (e.g. a token that loses schema-read access), and any unexpected shape issue here is caught too: a cosmetic feature must never fail the run.
- api.scripts.shopify_catalog_reconciliation.attach_creation_attempts(details: dict[str, Any], store: api.worker.run_store.RunStore) None¶
Best-effort: for each entry in
models_missing_in_shopify, note the most recentcreate_product_shopifyrun for that same Model, if any.A Model showing up here as “missing” might not be untried at all – it could already have been attempted and be failing for a knowable reason (bad data, a stale Shopify desync, an image upload conflict), which is very different from “nobody has tried yet”. Never raises – a cosmetic enrichment must never fail the reconciliation run itself.
- api.scripts.shopify_catalog_reconciliation.attach_update_attempts(details: dict[str, Any], store: api.worker.run_store.RunStore) None¶
Best-effort: for each entry in
variations_missing_in_shopify, note the most recentupdate_productrun for that same Variation, if any (matched via that run’s ownrecord_id– its default, per-Variation entry mode; a bulk model_id-mode run isn’t attributed back to its individual Variations here). Same rationale as attach_creation_attempts: “missing” doesn’t mean “untried”. Never raises – a cosmetic enrichment must never fail the reconciliation run.
- api.scripts.shopify_catalog_reconciliation.attach_documentation_attempts(details: dict[str, Any], store: api.worker.run_store.RunStore) None¶
Best-effort: for each Model in the missing/outdated documentation lists, note its most recent
update_productrun that actually tried to sync documentation – matched by that run’smodel_id, which both entry modes record. A run that found no PDF in Airtable at the time (status “absent”/”unchanged”) isn’t a documentation attempt and is ignored, so a stale pre-PDF run can’t pose as “synced but still missing”. Never raises – same rationale as attach_creation_attempts.
- api.scripts.shopify_catalog_reconciliation.NOT_A_VENDRE_DETAIL_KEYS = ('shopify_products_not_a_vendre', 'shopify_variants_not_a_vendre')¶
- api.scripts.shopify_catalog_reconciliation.alert_not_a_vendre(details: dict[str, Any]) None¶
One email per run listing what’s on Shopify but shouldn’t be.
- api.scripts.shopify_catalog_reconciliation.UPDATE_VARIATION_DETAIL_KEYS = ('variations_missing_in_shopify', 'a_vendre_units_missing_variant', 'a_vendre_quantity_mismatches')¶
- api.scripts.shopify_catalog_reconciliation.UPDATE_MODEL_DETAIL_KEYS = ('documentation_missing_in_shopify', 'documentation_outdated_in_shopify',...¶
- api.scripts.shopify_catalog_reconciliation.auto_fix(details: dict[str, Any], variations: list[api.domain.catalog.Variation]) dict[str, list[str]]¶
Queues the same runs the dashboard’s manual buttons do: create_product_shopify for each Model missing on Shopify, and one update_product per Model (by model_id, so a Model with several broken Variations is synced once) for stock, variant and documentation discrepancies. Returns what was queued; never raises – a failed enqueue must not fail the reconciliation run itself.
- class api.scripts.shopify_catalog_reconciliation.ShopifyCatalogReconciliation¶
Compares the Airtable sellable catalog against Shopify, then queues create/update_product for what they can fix.
- name = 'shopify_catalog_reconciliation'¶
- schedule¶
- is_configured() bool¶
- run(previous_snapshot: dict[str, Any] | None = None, report_stage: api.scripts.base.StageReporter = lambda stage: ..., **kwargs: Any) tuple[api.scripts.base.ScriptResult, dict[str, Any] | None]¶