From f92abf94c8b5618b3efec3984e0317f9cd2adac5 Mon Sep 17 00:00:00 2001 From: thug0bin Date: Sun, 8 Mar 2026 18:14:39 +0900 Subject: [PATCH] =?UTF-8?q?fix(scripts):=20SQLAlchemy=20=ED=8A=B8=EB=9E=9C?= =?UTF-8?q?=EC=9E=AD=EC=85=98=20=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit autobegin 상태에서 begin() 재호출 에러 → engine.begin() 컨텍스트 매니저로 변경. 189건 PostgreSQL weight_min_kg/weight_max_kg 업데이트 완료. Co-Authored-By: Claude Opus 4.6 --- backend/scripts/fill_weight_from_dosage.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/backend/scripts/fill_weight_from_dosage.py b/backend/scripts/fill_weight_from_dosage.py index 495d896..fe86261 100644 --- a/backend/scripts/fill_weight_from_dosage.py +++ b/backend/scripts/fill_weight_from_dosage.py @@ -524,23 +524,20 @@ def main(): # ── DB 업데이트 ── if not dry_run and updates: print(f'\n DB 업데이트 시작...') - tx = conn.begin() - try: + conn.close() + with pg.begin() as tx_conn: for apc_code, wmin, wmax, _, _ in updates: - conn.execute(text(''' + tx_conn.execute(text(''' UPDATE apc SET weight_min_kg = :wmin, weight_max_kg = :wmax WHERE apc = :apc '''), {'wmin': wmin, 'wmax': wmax, 'apc': apc_code}) - tx.commit() - print(f' 완료: {len(updates)}건 업데이트') - except Exception as e: - tx.rollback() - print(f' 오류 발생, 롤백: {e}') + print(f' 완료: {len(updates)}건 업데이트') elif not dry_run and not updates: print('\n 업데이트할 항목이 없습니다.') - - conn.close() + conn.close() + else: + conn.close() print('\n완료.')