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 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: if model_.reference and model_.reference.parent:
# Try adding parent_name as prefix # Try adding parent_name as prefix
new_name = ( new_name = (
@@ -1125,7 +1126,7 @@ class TypeManager:
else: else:
# Try adding suffix from datatype name # Try adding suffix from datatype name
new_name = name + model_data_type.__class__.__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: if new_name not in unique_models:
# New name is still unused # New name is still unused
@@ -1142,44 +1143,54 @@ class TypeManager:
) )
+ name + 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 unique_models[new_other_name] = other_model
elif isinstance(model_data_type, Struct): else:
# This is already an exceptional case (identity.mapping if model_.reference.hash_ == unique_models[new_name].hash_:
# with remote being oneOf with multiple structs) # not sure whether the new name should be save somewhere to be properly used in cli
# Try to make a name consisting of props self.ignored_models.append(model_.reference)
props = model_data_type.fields.keys() elif isinstance(model_data_type, Struct):
new_new_name = name + "".join( # This is already an exceptional case (identity.mapping
x.title() for x in props # with remote being oneOf with multiple structs)
).replace("_", "") # Try to make a name consisting of props
if new_new_name not in unique_models: props = model_data_type.fields.keys()
for other_ref, other_model in self.refs.items(): new_new_name = name + "".join(
other_name = getattr(other_model, "name", None) x.title() for x in props
if not other_name: ).replace("_", "")
continue if new_new_name not in unique_models:
if other_name in [name, new_name] and isinstance( for other_ref, other_model in self.refs.items():
other_model, Struct other_name = getattr(other_model, "name", None)
): if not other_name:
# rename first occurence to the same scheme continue
props = other_model.fields.keys() if other_name in [
new_other_name = name + "".join( name,
x.title() for x in props new_name,
).replace("_", "") ] and isinstance(other_model, Struct):
other_model.name = new_other_name # rename first occurence to the same scheme
unique_models[new_other_name] = ( props = other_model.fields.keys()
model_.reference new_other_name = name + "".join(
) x.title() for x in props
).replace("_", "")
other_model.name = new_other_name
unique_models[new_other_name] = (
model_.reference
)
# unique_models.pop(new_name, None)
model_data_type.name = new_new_name model_data_type.name = new_new_name
unique_models[new_new_name] = model_.reference unique_models[new_new_name] = model_.reference
else:
raise RuntimeError(
f"Model name {new_new_name} is already present"
)
else: else:
raise RuntimeError( raise RuntimeError(
f"Model name {new_new_name} is already present" f"Model name {new_name} is already present as {type(model_data_type)}"
) )
else:
raise RuntimeError(
f"Model name {new_name} is already present"
)
elif ( elif (
name name
and name in unique_models and name in unique_models

2592
uv.lock generated

File diff suppressed because it is too large Load Diff