fix:修复数据库问题

This commit is contained in:
SengokuCola
2026-04-07 21:43:07 +08:00
parent 4849c29b68
commit 1a617a151b
2 changed files with 104 additions and 11 deletions

View File

@@ -49,7 +49,11 @@ class ImageManager:
"""根据哈希获取图片记录。"""
with get_db_session() as session:
statement = select(Images).filter_by(image_hash=image_hash, image_type=ImageType.IMAGE).limit(1)
return session.exec(statement).first()
record = session.exec(statement).first()
if record is not None:
# 返回会话外使用的只读记录,避免在会话关闭后触发属性刷新。
session.expunge(record)
return record
def _normalize_image_registration_fields(self, record: Images) -> bool:
"""Normalize accidental emoji registration fields on image records."""