修复业务模型无法更新的bug

main
周平 10 months ago
parent a034aa4bf6
commit 1c04b32028

@ -127,9 +127,12 @@ class EnterpriseBusiModelRepository(object):
data['base_models'] = json.dumps(base_model)
with get_session() as session:
try:
session.query(EnterpriseBusiModel).filter(EnterpriseBusiModel.id == data['id']).update(data)
# 过滤不必要的字段
valid_columns = {col.name for col in EnterpriseBusiModel.__table__.columns}
filtered_data = {key: value for key, value in data.items() if key in valid_columns}
session.query(EnterpriseBusiModel).filter(EnterpriseBusiModel.id == data['id']).update(filtered_data)
except Exception as e:
logging.error("Failed to edit device")
logging.error("Failed to edit device, error: {}".format(e))
session.commit()
return

@ -113,6 +113,8 @@ class EnterpriseDeviceRepository(object):
device_id = device["id"]
with get_session() as session:
try:
# valid_columns = {col.name for col in EnterpriseDevice.__table__.columns}
# filtered_data = {key: value for key, value in device.items() if key in valid_columns}
session.query(EnterpriseDevice).filter(
EnterpriseDevice.id == device_id
).update(device)

@ -268,7 +268,7 @@ class InfoHandler(APIHandler):
text(
"""
select
m.name, m.model_type, m.comment, m.update_time,
m.name, m.model_type, m.default_version, m.comment, m.update_time,
mc.id as classification_id, mc.name as classification_name
from model m, model_classification mc
where m.id=:id and m.classification=mc.id
@ -284,6 +284,7 @@ class InfoHandler(APIHandler):
data = {
"name": result["name"],
"model_type": result["model_type"],
"default_version": result["default_version"],
"classification_id": result["classification_id"],
"classification_name": result["classification_name"],
"comment": result["comment"],
@ -621,6 +622,11 @@ class VersionSetDefaultHandler(APIHandler):
text("update model_version set is_default=1 where id=:id"),
{"id": version_id},
)
conn.execute(
text("update model m set m.default_version=(select version from model_version v where v.id=:vid) "
"where m.id=:mid"),
{"vid": version_id, "mid": model_id}
)
conn.commit()
self.finish()

@ -190,7 +190,7 @@ class EditHandler(APIHandler):
"""
@authenticated
def post(self):
busimodel_id = self.get_argument("id")
busimodel_id = self.get_int_argument("id")
if not busimodel_id:
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数错误")

@ -293,7 +293,8 @@ class EntityInfoHandler(APIHandler):
"province": row["province"],
"city": row["city"],
"addr": row["addr"],
"industry": row["industry"],
"industry": consts.industry_map[row["industry"]],
"expire_at": "",
"contact": row["contact"],
"phone": row["phone"],
"summary": row["summary"],

Loading…
Cancel
Save