From 1ccec767d147e1db4d854d8c45f2bc185cc20906 Mon Sep 17 00:00:00 2001 From: CI Bot Date: Mon, 13 Jul 2026 08:10:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(worker):=20=E4=BF=AE=E5=A4=8D=20dedup=20fin?= =?UTF-8?q?gerprint=20JSON=20=E5=BA=8F=E5=88=97=E5=8C=96=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=20-=20np.float32=20=E8=BD=AC=E5=8E=9F=E7=94=9F=20float?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:cv2.normalize() 返回 np.float32 数组,color_histograms 直接存进 dict 后 SQLAlchemy JSON 序列化时报 'float32 is not JSON serializable' 修复:VideoFingerprint.to_dict() 中统一转 Python 原生类型 - color_histograms: np.float32 → float - duration: 统一转 float - resolution: np.int32 → int --- apps/worker/video_processing/dedup.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) mode change 100644 => 100755 apps/worker/video_processing/dedup.py diff --git a/apps/worker/video_processing/dedup.py b/apps/worker/video_processing/dedup.py old mode 100644 new mode 100755 index 9e7a992d3..e71d96cb8 --- a/apps/worker/video_processing/dedup.py +++ b/apps/worker/video_processing/dedup.py @@ -93,12 +93,16 @@ class VideoFingerprint: resolution: tuple[int, int] def to_dict(self) -> dict: + # 注意:color_histograms 里的值可能是 np.float32(来自 cv2.normalize), + # 直接存进 dict 后 SQLAlchemy JSON 序列化会报 "float32 is not JSON serializable"。 + # 这里统一转成 Python 原生 float。 + native_histograms = [[float(v) for v in hist] for hist in self.color_histograms] return { "md5": self.md5, "keyframe_phashes": self.keyframe_phashes, - "color_histograms": self.color_histograms, - "duration": self.duration, - "resolution": list(self.resolution), + "color_histograms": native_histograms, + "duration": float(self.duration), + "resolution": [int(self.resolution[0]), int(self.resolution[1])], } -- 2.54.0