|
|
@@ -638,20 +638,28 @@ async def hazard(
|
|
|
json.dumps(record_payload, ensure_ascii=False, default=str),
|
|
|
)
|
|
|
|
|
|
- record = RecognitionRecord(**record_payload)
|
|
|
- db.add(record)
|
|
|
- logger.info("[hazard][%s] record added to session, committing db transaction", request_id)
|
|
|
- db.commit()
|
|
|
- logger.info("[hazard][%s] db commit success, refreshing record", request_id)
|
|
|
- db.refresh(record)
|
|
|
- logger.info(
|
|
|
- "[hazard][%s] record saved successfully: id=%r, current_step=%r, created_at=%r, updated_at=%r",
|
|
|
- request_id,
|
|
|
- getattr(record, "id", None),
|
|
|
- getattr(record, "current_step", None),
|
|
|
- getattr(record, "created_at", None),
|
|
|
- getattr(record, "updated_at", None),
|
|
|
- )
|
|
|
+ record_id_value = None
|
|
|
+ if data.save_history:
|
|
|
+ record = RecognitionRecord(**record_payload)
|
|
|
+ db.add(record)
|
|
|
+ logger.info("[hazard][%s] record added to session, committing db transaction", request_id)
|
|
|
+ db.commit()
|
|
|
+ logger.info("[hazard][%s] db commit success, refreshing record", request_id)
|
|
|
+ db.refresh(record)
|
|
|
+ record_id_value = getattr(record, "id", None)
|
|
|
+ logger.info(
|
|
|
+ "[hazard][%s] record saved successfully: id=%r, current_step=%r, created_at=%r, updated_at=%r",
|
|
|
+ request_id,
|
|
|
+ record_id_value,
|
|
|
+ getattr(record, "current_step", None),
|
|
|
+ getattr(record, "created_at", None),
|
|
|
+ getattr(record, "updated_at", None),
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ logger.info(
|
|
|
+ "[hazard][%s] save_history=False, skipping record save",
|
|
|
+ request_id,
|
|
|
+ )
|
|
|
except Exception as e:
|
|
|
logger.error(
|
|
|
"[hazard][%s] 识别失败(保存记录阶段): error=%s, traceback=%s",
|
|
|
@@ -694,7 +702,7 @@ async def hazard(
|
|
|
"display_labels": display_labels,
|
|
|
"third_scenes": third_scene_names,
|
|
|
"element_hazards": element_hazards,
|
|
|
- "record_id": getattr(record, "id", None),
|
|
|
+ "record_id": record_id_value,
|
|
|
}
|
|
|
logger.info(
|
|
|
"[hazard][%s] response prepared successfully: %s",
|