From 53ff943ac377ea4fef89fe585227e81316093ae9 Mon Sep 17 00:00:00 2001 From: yeuimu <2197651308@qq.com> Date: Thu, 23 Jul 2026 08:43:27 +0000 Subject: [PATCH] fix: db.py SQL (<>ALL, escape %% in LIKE) + incremental_sync tz-aware compare --- flows/riin/incremental_sync.py | 2 ++ flows/sds/incremental_sync.py | 2 ++ flows/shared/db.py | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/flows/riin/incremental_sync.py b/flows/riin/incremental_sync.py index 9e696d0..28d7645 100644 --- a/flows/riin/incremental_sync.py +++ b/flows/riin/incremental_sync.py @@ -37,6 +37,8 @@ def upsert_records(raw_orders: list) -> dict: def riin_incremental_sync() -> dict: db = SyncDB() latest = db.get_latest_ordered_at("RIIN") + if latest is not None and latest.tzinfo is not None: + latest = latest.replace(tzinfo=None) now = datetime.now() from_dt = floor_to_hour(latest) if latest else floor_to_hour(now) to_dt = now diff --git a/flows/sds/incremental_sync.py b/flows/sds/incremental_sync.py index 64bbb07..1a6232c 100644 --- a/flows/sds/incremental_sync.py +++ b/flows/sds/incremental_sync.py @@ -40,6 +40,8 @@ def upsert_records(raw_orders: list) -> dict: def sds_incremental_sync() -> dict: db = SyncDB() latest = db.get_latest_ordered_at("SDS") + if latest is not None and latest.tzinfo is not None: + latest = latest.replace(tzinfo=None) now = datetime.now() from_dt = floor_to_hour(latest) if latest else floor_to_hour(now) if from_dt >= now: diff --git a/flows/shared/db.py b/flows/shared/db.py index 83331d2..354cd38 100644 --- a/flows/shared/db.py +++ b/flows/shared/db.py @@ -46,7 +46,7 @@ class SyncDB: with conn.cursor() as cur: cur.execute( 'SELECT DISTINCT "orderNo" FROM "Orders" WHERE "systemName"=%s ' - 'AND "systemStatus" IS DISTINCT FROM ALL %s', + 'AND ("systemStatus" IS NULL OR "systemStatus" <> ALL %s)', (system_name, exclude_statuses), ) rows = cur.fetchall() @@ -92,7 +92,7 @@ class SyncDB: cur.execute( 'SELECT DISTINCT o."orderNo", o."createdAt" FROM "Orders" o ' 'JOIN "Goods" g ON g."orderNo"=o."orderNo" AND g."createdAt"=o."createdAt" ' - 'WHERE o."systemName"=%s AND o."systemStatus"=ANY(%s) AND g."productionNo" LIKE \'100%\'', + 'WHERE o."systemName"=%s AND o."systemStatus"=ANY(%s) AND g."productionNo" LIKE \'100%%\'', (system_name, statuses), ) rows = cur.fetchall()