Skip to content
Snippets Groups Projects
Commit 1b3f81a8 authored by I. Nüske's avatar I. Nüske
Browse files

MNT: Fix entity_name_id_equivalency recursion

parent f8ad701c
No related branches found
No related tags found
2 merge requests!159Release 0.16.o,!155Review filter lists and compare_entities
Pipeline #56987 passed with warnings
...@@ -321,7 +321,8 @@ def compare_entities(entity0: Entity, entity1: Entity, ...@@ -321,7 +321,8 @@ def compare_entities(entity0: Entity, entity1: Entity,
# Compare Entities # Compare Entities
if (compare_referenced_records and if (compare_referenced_records and
isinstance(val0, Entity) and isinstance(val1, Entity)): isinstance(val0, Entity) and isinstance(val1, Entity)):
if empty_diff(val0, val1, False): if empty_diff(val0, val1, False,
entity_name_id_equivalency):
continue continue
# Compare Entity name and id # Compare Entity name and id
if entity_name_id_equivalency: if entity_name_id_equivalency:
...@@ -366,7 +367,8 @@ def compare_entities(entity0: Entity, entity1: Entity, ...@@ -366,7 +367,8 @@ def compare_entities(entity0: Entity, entity1: Entity,
# Recursive call to determine the differences between properties # Recursive call to determine the differences between properties
# Note: Can lead to infinite recursion if two properties have # Note: Can lead to infinite recursion if two properties have
# themselves or each other as subproperties # themselves or each other as subproperties
od, nd = compare_entities(comp1, comp2, compare_referenced_records) od, nd = compare_entities(comp1, comp2, compare_referenced_records,
entity_name_id_equivalency)
# We do not care about parents and properties here, discard # We do not care about parents and properties here, discard
od.pop("parents") od.pop("parents")
od.pop("properties") od.pop("properties")
...@@ -419,7 +421,8 @@ def compare_entities(entity0: Entity, entity1: Entity, ...@@ -419,7 +421,8 @@ def compare_entities(entity0: Entity, entity1: Entity,
def empty_diff(old_entity: Entity, new_entity: Entity, def empty_diff(old_entity: Entity, new_entity: Entity,
compare_referenced_records: bool = False) -> bool: compare_referenced_records: bool = False,
entity_name_id_equivalency: bool = False) -> bool:
"""Check whether the `compare_entities` found any differences between """Check whether the `compare_entities` found any differences between
old_entity and new_entity. old_entity and new_entity.
...@@ -431,10 +434,13 @@ def empty_diff(old_entity: Entity, new_entity: Entity, ...@@ -431,10 +434,13 @@ def empty_diff(old_entity: Entity, new_entity: Entity,
Whether to compare referenced records in case of both, `old_entity` and Whether to compare referenced records in case of both, `old_entity` and
`new_entity`, have the same reference properties and both have a Record `new_entity`, have the same reference properties and both have a Record
object as value. object as value.
entity_name_id_equivalency : bool, optional
If set to True, the comparison between an entity and an int or str also
checks whether the int/str matches the name or id of the entity, so
Entity(id=100) == 100 == "100".
""" """
olddiff, newdiff = compare_entities( olddiff, newdiff = compare_entities(old_entity, new_entity,
old_entity, new_entity, compare_referenced_records) compare_referenced_records, entity_name_id_equivalency)
for diff in [olddiff, newdiff]: for diff in [olddiff, newdiff]:
for key in ["parents", "properties"]: for key in ["parents", "properties"]:
if len(diff[key]) > 0: if len(diff[key]) > 0:
...@@ -499,8 +505,9 @@ def merge_entities(entity_a: Entity, ...@@ -499,8 +505,9 @@ def merge_entities(entity_a: Entity,
""" """
# Compare both entities: # Compare both entities:
diff_r1, diff_r2 = compare_entities( diff_r1, diff_r2 = compare_entities(entity_a, entity_b,
entity_a, entity_b, compare_referenced_records=merge_references_with_empty_diffs) entity_name_id_equivalency=merge_id_with_resolved_entity,
compare_referenced_records=merge_references_with_empty_diffs)
# Go through the comparison and try to apply changes to entity_a: # Go through the comparison and try to apply changes to entity_a:
for key in diff_r2["parents"]: for key in diff_r2["parents"]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment