Skip to content

Commit 8e93e1e

Browse files
committed
fix: handle None source_file_id in link_file method
1 parent fc89b91 commit 8e93e1e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

apps/knowledge/serializers/document.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,8 @@ class Batch(serializers.Serializer):
969969

970970
@staticmethod
971971
def link_file(source_file_id, document_id):
972+
if source_file_id is None:
973+
return
972974
source_file = QuerySet(File).filter(id=source_file_id).first()
973975
if source_file:
974976
# 获取原始文件内容
@@ -1016,7 +1018,7 @@ def batch_save(self, instance_list: List[Dict], with_valid=True):
10161018
)
10171019
# 保存文档和文件的关系
10181020
document_instance = document_paragraph_dict_model.get('document')
1019-
self.link_file(document['source_file_id'], document_instance.id)
1021+
self.link_file(document.get('source_file_id'), document_instance.id)
10201022
document_model_list.append(document_instance)
10211023
for paragraph in document_paragraph_dict_model.get('paragraph_model_list'):
10221024
paragraph_model_list.append(paragraph)

0 commit comments

Comments
 (0)