Skip to content

Commit 27b7458

Browse files
committed
chore: update document.py to create and associate new source file ID in metadata
1 parent 4d081d9 commit 27b7458

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

apps/knowledge/serializers/document.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,13 +1539,25 @@ def replace(self):
15391539

15401540
if not source_file:
15411541
# 不存在手动关联一个文档
1542+
new_source_file_id = uuid.uuid7()
15421543
new_source_file = File(
1543-
id=uuid.uuid7(),
1544+
id=new_source_file_id,
15441545
file_name=file.name,
15451546
source_type=FileSourceType.DOCUMENT,
15461547
source_id=self.data.get('document_id'),
15471548
)
15481549
new_source_file.save(file.read())
1550+
# 更新Document的meta字段
1551+
QuerySet(Document).filter(id=self.data.get('document_id')).update(
1552+
meta=Func(
1553+
F("meta"),
1554+
Value(["source_file_id"]),
1555+
Value(json.dumps(str(new_source_file_id))),
1556+
Value(True), # create_missing = true
1557+
function="jsonb_set",
1558+
output_field=JSONField(),
1559+
)
1560+
)
15491561
else:
15501562
# 获取原文件的sha256_hash
15511563
original_hash = source_file.sha256_hash

0 commit comments

Comments
 (0)