袁威 2 هفته پیش
والد
کامیت
99e6ece20d
1فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 5 1
      app/api/formate_xy.py

+ 5 - 1
app/api/formate_xy.py

@@ -478,11 +478,15 @@ async def update_image_modified_json(
             with db_conn.cursor() as cursor:
                 review_state = 2
                 # 更新指定 card_id 的 review_state 字段
+                # 注意:MySQL 在“值未变化”时 rowcount 可能为 0,这不代表记录不存在。
                 query_update = f"UPDATE {settings.DB_CARD_TABLE_NAME} SET review_state = %s WHERE id = %s"
                 cursor.execute(query_update, (review_state, card_id_to_update))
 
                 if cursor.rowcount == 0:
-                    raise HTTPException(status_code=404, detail=f"ID为 {card_id_to_update} 的卡牌未找到。")
+                    cursor.execute(f"SELECT 1 FROM {settings.DB_CARD_TABLE_NAME} WHERE id = %s LIMIT 1",
+                                   (card_id_to_update,))
+                    if not cursor.fetchone():
+                        raise HTTPException(status_code=404, detail=f"ID为 {card_id_to_update} 的卡牌未找到。")
 
                 db_conn.commit()
                 logger.info(f"卡牌 ID {card_id_to_update} 的审核状态已成功修改为 {review_state}。")