You've already forked DataMate
fix(annotation): 修复项目映射查询逻辑错误
- 移除旧的映射服务查询方式,改为直接查询 ORM 模型获取原始数据 - 更新配置字段读取逻辑以使用新的 ORM 对象 - 修复更新无变化时的响应数据返回问题 - 添加软删除过滤条件确保只返回未删除的项目记录 - 统一数据访问方式提高查询效率和代码一致性
This commit is contained in:
@@ -406,10 +406,16 @@ async def update_mapping(
|
|||||||
|
|
||||||
service = DatasetMappingService(db)
|
service = DatasetMappingService(db)
|
||||||
|
|
||||||
# 使用 mapping UUID 查询映射记录
|
# 直接查询 ORM 模型获取原始数据
|
||||||
mapping = await service.get_mapping_by_uuid(project_id)
|
result = await db.execute(
|
||||||
|
select(LabelingProject).where(
|
||||||
|
LabelingProject.id == project_id,
|
||||||
|
LabelingProject.deleted_at.is_(None)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
mapping_orm = result.scalar_one_or_none()
|
||||||
|
|
||||||
if not mapping:
|
if not mapping_orm:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=404,
|
status_code=404,
|
||||||
detail=f"Mapping not found: {project_id}"
|
detail=f"Mapping not found: {project_id}"
|
||||||
@@ -422,8 +428,8 @@ async def update_mapping(
|
|||||||
|
|
||||||
# 从 configuration 字段中读取和更新 description 和 label_config
|
# 从 configuration 字段中读取和更新 description 和 label_config
|
||||||
configuration = {}
|
configuration = {}
|
||||||
if mapping.configuration:
|
if mapping_orm.configuration:
|
||||||
configuration = mapping.configuration.copy() if isinstance(mapping.configuration, dict) else {}
|
configuration = mapping_orm.configuration.copy() if isinstance(mapping_orm.configuration, dict) else {}
|
||||||
|
|
||||||
if request.description is not None:
|
if request.description is not None:
|
||||||
configuration["description"] = request.description
|
configuration["description"] = request.description
|
||||||
@@ -438,10 +444,11 @@ async def update_mapping(
|
|||||||
|
|
||||||
if not update_values:
|
if not update_values:
|
||||||
# 没有要更新的字段,直接返回当前数据
|
# 没有要更新的字段,直接返回当前数据
|
||||||
|
response_data = await service.get_mapping_by_uuid(project_id)
|
||||||
return StandardResponse(
|
return StandardResponse(
|
||||||
code=200,
|
code=200,
|
||||||
message="success",
|
message="success",
|
||||||
data=mapping
|
data=response_data
|
||||||
)
|
)
|
||||||
|
|
||||||
# 执行更新
|
# 执行更新
|
||||||
|
|||||||
Reference in New Issue
Block a user