优化资源分配逻辑,避免在反序列化时因名称冲突导致的错误处理

This commit is contained in:
ZiWei
2026-04-28 11:27:58 +08:00
parent 7027bd5ed1
commit 70c6685283
2 changed files with 9 additions and 3 deletions

View File

@@ -179,6 +179,11 @@ class ItemizedCarrier(ResourcePLR):
idx = i
break
if idx is None:
# 反序列化时无法匹配 site名称或坐标均不符退回父类默认分配不更新 site 跟踪
super().assign_child_resource(resource, location=location, reassign=reassign)
return
if not reassign and self.sites[idx] is not None:
raise ValueError(f"a site with index {idx} already exists")
location = list(self.child_locations.values())[idx]

View File

@@ -611,9 +611,10 @@ class ResourceTreeSet(object):
}
if has_model:
d["model"] = res.config.get("model", None)
# 防止 Deck 子类在 __init__ 中调用 setup() 预分配子资源
# PLR deserialize 从 children 列表再次分配同名资源产生命名冲突
if "setup" in d:
# 仅当 PLR dict 中含有子节点时才禁用 setup()
# 防止 setup() 预分配子资源后 PLR deserialize 再次分配同名资源产生命名冲突
# 若 children 为空,则保留 setup=True依赖 setup() 来初始化仓库。
if "setup" in d and d.get("children"):
d["setup"] = False
return d