Hopefully address nested structures renaming race

Sometimes (and now very often) there is some race in the deep nested
structures rename handling. Apparently during renaming the wrong object
was modified causing it not to find referred entity later causing some
confusions depending on the order in which entities are processed.
Additionally when enum with the same name occur we should also look
whether the schema hash equals, in which case it is safe to simply skip
the schema completely).

Change-Id: I1bbb5f1e4f702ab54f72cdb70418b04567047187
This commit is contained in:
Artem Goncharov
2025-05-17 12:10:15 +02:00
parent 85c09cd60e
commit d201f9a6d9
2 changed files with 1341 additions and 1332 deletions

View File

@@ -1112,7 +1112,8 @@ class TypeManager:
or name == self.root_name
)
):
# There is already a model with this name.
# There is already a model with this name (i.e.
# SessionPersistence.type vs HealthMonitor.type).
if model_.reference and model_.reference.parent:
# Try adding parent_name as prefix
new_name = (
@@ -1125,7 +1126,7 @@ class TypeManager:
else:
# Try adding suffix from datatype name
new_name = name + model_data_type.__class__.__name__
logging.debug(f"rename {name} to {new_name}")
logging.debug(f"try renaming {name} to {new_name}")
if new_name not in unique_models:
# New name is still unused
@@ -1142,8 +1143,16 @@ class TypeManager:
)
+ name
)
other_model.name = new_other_name
logging.debug(
f"Renaming also {other_model} into {new_other_name} for consistency"
)
self.refs[other_model].name = new_other_name
# other_model.name = new_other_name
unique_models[new_other_name] = other_model
else:
if model_.reference.hash_ == unique_models[new_name].hash_:
# not sure whether the new name should be save somewhere to be properly used in cli
self.ignored_models.append(model_.reference)
elif isinstance(model_data_type, Struct):
# This is already an exceptional case (identity.mapping
# with remote being oneOf with multiple structs)
@@ -1157,9 +1166,10 @@ class TypeManager:
other_name = getattr(other_model, "name", None)
if not other_name:
continue
if other_name in [name, new_name] and isinstance(
other_model, Struct
):
if other_name in [
name,
new_name,
] and isinstance(other_model, Struct):
# rename first occurence to the same scheme
props = other_model.fields.keys()
new_other_name = name + "".join(
@@ -1169,6 +1179,7 @@ class TypeManager:
unique_models[new_other_name] = (
model_.reference
)
# unique_models.pop(new_name, None)
model_data_type.name = new_new_name
unique_models[new_new_name] = model_.reference
@@ -1178,7 +1189,7 @@ class TypeManager:
)
else:
raise RuntimeError(
f"Model name {new_name} is already present"
f"Model name {new_name} is already present as {type(model_data_type)}"
)
elif (
name

2592
uv.lock generated

File diff suppressed because it is too large Load Diff