fix: dataset validate默认sql_query为空/缺少查询参数提示

This commit is contained in:
caoqianming 2023-07-06 16:58:04 +08:00
parent e51d19fac0
commit ad0c3cdd7c
2 changed files with 3 additions and 1 deletions

View File

@ -11,7 +11,7 @@ class DatasetCreateUpdateSerializer(CustomModelSerializer):
exclude = EXCLUDE_FIELDS
def validate(self, attrs):
sql_query = attrs['sql_query']
sql_query = attrs.get('sql_query', '')
if sql_query:
check_sql_safe(sql_query)
return attrs

View File

@ -70,6 +70,8 @@ class DatasetViewSet(CustomModelViewSet):
if dt.sql_query:
sql_f_ = check_sql_safe(dt.sql_query.format(**query))
if '{' in sql_f_:
raise ParseError('未指定查询参数')
sql_f_l = sql_f_.strip(';').split(';')
hash_k = hash(sql_f_.strip(';'))
hash_v = cache.get(hash_k, None)