修复 部分 json 数据不能识别
修复 标签字段比对不完全
This commit is contained in:
@@ -39,6 +39,31 @@ from .database import ensure_database, get_db_connection
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def convert_bytes_to_str(obj):
|
||||
"""递归转换对象中的bytes类型为字符串,用于JSON序列化
|
||||
|
||||
Args:
|
||||
obj: 需要转换的对象(可以是dict, list或其他类型)
|
||||
|
||||
Returns:
|
||||
转换后的对象,所有bytes类型都被转换为hex字符串
|
||||
"""
|
||||
if isinstance(obj, bytes):
|
||||
# 将bytes转换为十六进制字符串
|
||||
return obj.hex()
|
||||
elif isinstance(obj, dict):
|
||||
# 递归处理字典
|
||||
return {key: convert_bytes_to_str(value) for key, value in obj.items()}
|
||||
elif isinstance(obj, list):
|
||||
# 递归处理列表
|
||||
return [convert_bytes_to_str(item) for item in obj]
|
||||
elif isinstance(obj, tuple):
|
||||
# 递归处理元组
|
||||
return tuple(convert_bytes_to_str(item) for item in obj)
|
||||
else:
|
||||
# 其他类型直接返回
|
||||
return obj
|
||||
|
||||
# Cassandra数据库默认配置模板
|
||||
# 注意:此配置不包含敏感信息,仅作为UI表单的初始模板使用
|
||||
DEFAULT_CONFIG = {
|
||||
@@ -233,6 +258,9 @@ def save_redis_query_history(name, description, cluster1_config, cluster2_config
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
# 转换可能包含bytes类型的数据
|
||||
raw_results = convert_bytes_to_str(raw_results) if raw_results else None
|
||||
|
||||
cursor.execute('''
|
||||
INSERT INTO redis_query_history
|
||||
(name, description, cluster1_config, cluster2_config, query_options, query_keys,
|
||||
@@ -600,6 +628,11 @@ def save_query_history(name, description, pro_config, test_config, query_config,
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
# 转换可能包含bytes类型的数据
|
||||
raw_results = convert_bytes_to_str(raw_results) if raw_results else None
|
||||
differences_data = convert_bytes_to_str(differences_data) if differences_data else None
|
||||
identical_data = convert_bytes_to_str(identical_data) if identical_data else None
|
||||
|
||||
cursor.execute('''
|
||||
INSERT INTO query_history
|
||||
(name, description, pro_config, test_config, query_config, query_keys,
|
||||
|
Reference in New Issue
Block a user