mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-06-12 19:21:05 +08:00
fix: normalize subscribe integer flags before persistence
This commit is contained in:
@@ -6,6 +6,19 @@ from app.db import DbOper
|
||||
from app.db.models.subscribe import Subscribe
|
||||
from app.db.models.subscribehistory import SubscribeHistory
|
||||
|
||||
INTEGER_FLAG_FIELDS = ("best_version", "best_version_full", "search_imdbid", "manual_total_episode")
|
||||
|
||||
|
||||
def _normalize_integer_flags(payload: dict, fields: Tuple[str, ...] = INTEGER_FLAG_FIELDS) -> dict:
|
||||
"""
|
||||
将历史兼容的布尔开关转换为整型值,避免 PostgreSQL 严格类型检查失败。
|
||||
"""
|
||||
normalized_payload = dict(payload)
|
||||
for field in fields:
|
||||
if isinstance(normalized_payload.get(field), bool):
|
||||
normalized_payload[field] = int(normalized_payload[field])
|
||||
return normalized_payload
|
||||
|
||||
|
||||
class SubscribeOper(DbOper):
|
||||
"""
|
||||
@@ -37,6 +50,7 @@ class SubscribeOper(DbOper):
|
||||
"search_imdbid": 1 if kwargs.get('search_imdbid') else 0,
|
||||
"date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||
})
|
||||
kwargs = _normalize_integer_flags(kwargs)
|
||||
if not subscribe:
|
||||
subscribe = Subscribe(**kwargs)
|
||||
subscribe.create(self._db)
|
||||
@@ -74,6 +88,7 @@ class SubscribeOper(DbOper):
|
||||
"search_imdbid": 1 if kwargs.get('search_imdbid') else 0,
|
||||
"date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||
})
|
||||
kwargs = _normalize_integer_flags(kwargs)
|
||||
if not subscribe:
|
||||
subscribe = Subscribe(**kwargs)
|
||||
await subscribe.async_create(self._db)
|
||||
@@ -160,6 +175,7 @@ class SubscribeOper(DbOper):
|
||||
"""
|
||||
subscribe = self.get(sid)
|
||||
if subscribe:
|
||||
payload = _normalize_integer_flags(payload)
|
||||
subscribe.update(self._db, payload)
|
||||
return subscribe
|
||||
|
||||
@@ -188,6 +204,7 @@ class SubscribeOper(DbOper):
|
||||
"""
|
||||
# 去除kwargs中 SubscribeHistory 没有的字段
|
||||
kwargs = {k: v for k, v in kwargs.items() if hasattr(SubscribeHistory, k)}
|
||||
kwargs = _normalize_integer_flags(kwargs)
|
||||
# 更新完成订阅时间
|
||||
kwargs.update({"date": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())})
|
||||
# 去掉主键
|
||||
|
||||
Reference in New Issue
Block a user