From 4a4e53602be6eb99b550461b93337b16d4a9d770 Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Sat, 18 Jul 2026 04:47:46 +0000 Subject: [PATCH] Guard against missing marketplace tables when recording inventory operations --- pos/services/inventory_engine.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pos/services/inventory_engine.py b/pos/services/inventory_engine.py index 8b28d1a..2b70263 100644 --- a/pos/services/inventory_engine.py +++ b/pos/services/inventory_engine.py @@ -122,16 +122,24 @@ def record_operation(conn, inventory_id, branch_id, operation_type, quantity, )) op_id = cur.fetchone()[0] - # Queue ML stock sync if this product has an active ML listing + # Queue ML stock sync if this product has an active ML listing. + # Skip gracefully if the marketplace tables do not exist in this tenant. cur.execute(""" - INSERT INTO meli_sync_queue (inventory_id, action, status) - SELECT %s, 'stock_update', 'pending' - WHERE EXISTS ( - SELECT 1 FROM marketplace_listings - WHERE inventory_id = %s AND channel = 'mercadolibre' AND is_active = true - ) - ON CONFLICT DO NOTHING - """, (inventory_id, inventory_id)) + SELECT 1 FROM information_schema.tables + WHERE table_schema = 'public' + AND table_name IN ('marketplace_listings', 'meli_sync_queue') + LIMIT 1 + """) + if cur.fetchone(): + cur.execute(""" + INSERT INTO meli_sync_queue (inventory_id, action, status) + SELECT %s, 'stock_update', 'pending' + WHERE EXISTS ( + SELECT 1 FROM marketplace_listings + WHERE inventory_id = %s AND channel = 'mercadolibre' AND is_active = true + ) + ON CONFLICT DO NOTHING + """, (inventory_id, inventory_id)) cur.close() return op_id