Skip to content

Commit db58ed8

Browse files
committed
fix: allow null and blank values for status and order_by fields in document queries
--bug=1057473 --user=刘瑞斌 【知识库】文档列表通过列表字段筛选文档不生效 https://www.tapd.cn/62980211/s/1719702
1 parent efa2335 commit db58ed8

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

apps/knowledge/serializers/document.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import io
2-
import logging
32
import os
43
import re
54
import traceback
@@ -347,34 +346,36 @@ class Query(serializers.Serializer):
347346
# 知识库id
348347
workspace_id = serializers.CharField(required=True, label=_('workspace id'))
349348
knowledge_id = serializers.UUIDField(required=True, label=_('knowledge id'))
350-
name = serializers.CharField(required=False, max_length=128, min_length=1, allow_null=True, allow_blank=True,
351-
label=_('document name'))
352-
hit_handling_method = serializers.CharField(required=False, label=_('hit handling method'))
353-
is_active = serializers.BooleanField(required=False, label=_('document is active'))
349+
name = serializers.CharField(
350+
required=False, max_length=128, min_length=1, allow_null=True, allow_blank=True, label=_('document name')
351+
)
352+
hit_handling_method = serializers.CharField(
353+
required=False, label=_('hit handling method'), allow_null=True, allow_blank=True
354+
)
355+
is_active = serializers.BooleanField(required=False, label=_('document is active'), allow_null=True)
354356
task_type = serializers.IntegerField(required=False, label=_('task type'))
355-
status = serializers.CharField(required=False, label=_('status'))
356-
order_by = serializers.CharField(required=False, label=_('order by'))
357+
status = serializers.CharField(required=False, label=_('status'), allow_null=True, allow_blank=True)
358+
order_by = serializers.CharField(required=False, label=_('order by'), allow_null=True, allow_blank=True)
357359

358360
def get_query_set(self):
359361
query_set = QuerySet(model=Document)
360362
query_set = query_set.filter(**{'knowledge_id': self.data.get("knowledge_id")})
361363
if 'name' in self.data and self.data.get('name') is not None:
362364
query_set = query_set.filter(**{'name__icontains': self.data.get('name')})
363-
if 'hit_handling_method' in self.data and self.data.get('hit_handling_method') is not None:
365+
if 'hit_handling_method' in self.data and self.data.get('hit_handling_method') not in [None, '']:
364366
query_set = query_set.filter(**{'hit_handling_method': self.data.get('hit_handling_method')})
365367
if 'is_active' in self.data and self.data.get('is_active') is not None:
366368
query_set = query_set.filter(**{'is_active': self.data.get('is_active')})
367-
if 'status' in self.data and self.data.get(
368-
'status') is not None:
369+
if 'status' in self.data and self.data.get('status') is not None:
369370
task_type = self.data.get('task_type')
370-
status = self.data.get(
371-
'status')
371+
status = self.data.get('status')
372372
if task_type is not None:
373373
query_set = query_set.annotate(
374374
reversed_status=Reverse('status'),
375-
task_type_status=Substr('reversed_status', TaskType(task_type).value,
376-
1),
377-
).filter(task_type_status=State(status).value).values('id')
375+
task_type_status=Substr('reversed_status', TaskType(task_type).value, 1),
376+
).filter(
377+
task_type_status=State(status).value
378+
).values('id')
378379
else:
379380
if status != State.SUCCESS.value:
380381
query_set = query_set.filter(status__icontains=status)

apps/knowledge/views/document.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,11 @@ def get(self, request: Request, workspace_id: str, knowledge_id: str, current_pa
550550
'folder_id': request.query_params.get('folder_id'),
551551
'name': request.query_params.get('name'),
552552
'desc': request.query_params.get("desc"),
553-
'user_id': request.query_params.get('user_id')
553+
'user_id': request.query_params.get('user_id'),
554+
'status': request.query_params.get('status'),
555+
'is_active': request.query_params.get('is_active'),
556+
'hit_handling_method': request.query_params.get('hit_handling_method'),
557+
'order_by': request.query_params.get('order_by'),
554558
}
555559
).page(current_page, page_size))
556560

0 commit comments

Comments
 (0)