Skip to content
Snippets Groups Projects

Revert "Merge branch 'f-check-merge-entities' into 'dev'"

Merged Florian Spreckelsen requested to merge revert-5ce8e910 into dev
3 files
+ 44
175
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 5
32
@@ -178,8 +178,7 @@ def getCommitIn(folder):
return get_commit_in(folder)
def compare_entities(old_entity: Entity, new_entity: Entity,
compare_referenced_records: bool = False):
def compare_entities(old_entity: Entity, new_entity: Entity, compare_referenced_records: bool = False):
"""Compare two entites.
Return a tuple of dictionaries, the first index belongs to additional information for old
@@ -190,9 +189,8 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
- Information about properties:
- Each property lists either an additional property or a property with a changed:
- datatype
- unit
- importance or
- value
- value (not implemented yet)
In case of changed information the value listed under the respective key shows the
value that is stored in the respective entity.
@@ -202,9 +200,6 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
`compare_referenced_records = False` to prevent infinite recursion in case
of circular references).
NOTE: This function does not work for abstract properties! I.e. it is not possible
to directly compare two entities that are of class caosdb.Property.
Parameters
----------
old_entity, new_entity : Entity
@@ -217,12 +212,6 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
identical records are stored in different objects. Default is False.
"""
for entity in (old_entity, new_entity):
if isinstance(entity, Property):
raise NotImplementedError("The function compare_entities does not work for "
"comparing abstract properties.")
olddiff: Dict[str, Any] = {"properties": {}, "parents": []}
newdiff: Dict[str, Any] = {"properties": {}, "parents": []}
@@ -250,7 +239,7 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
if not old_entity_attr_exists and not new_entity_attr_exists:
continue
if ((old_entity_attr_exists != new_entity_attr_exists)
if ((old_entity_attr_exists ^ new_entity_attr_exists)
or (oldattr != newattr)):
if old_entity_attr_exists:
@@ -262,21 +251,9 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
# properties
for prop in old_entity.properties:
# Find the corresponding property in new_entity:
matching = [p for p in new_entity.properties if p.name == prop.name]
# This is needed for checking for multi properties in old_entity:
# TODO: is there a better way?
matching_old = [p for p in old_entity.properties if p.name == prop.name]
if len(matching_old) != 1:
raise NotImplementedError(
"Comparison not implemented for multi-properties.")
if len(matching) > 1:
raise NotImplementedError(
"Comparison not implemented for multi-properties.")
if len(matching) == 0:
# There is no matching property in new_entity:
olddiff["properties"][prop.name] = {}
elif len(matching) == 1:
newdiff["properties"][prop.name] = {}
@@ -306,7 +283,6 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
# scalar reference
if isinstance(prop.value, Entity) and isinstance(matching[0].value, Entity):
# explicitely not recursive to prevent infinite recursion
# TODO: why not use a recursion detection with a cache?
same_value = empty_diff(
prop.value, matching[0].value, compare_referenced_records=False)
# list of references
@@ -330,14 +306,11 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
newdiff["properties"].pop(prop.name)
olddiff["properties"].pop(prop.name)
# Check whether there are missing properties in old_entity, additionally
# check for multi-properties that are currently not supported:
for prop in new_entity.properties:
matching = [p for p in new_entity.properties if p.name == prop.name]
if len(matching) > 1:
else:
raise NotImplementedError(
"Comparison not implemented for multi-properties.")
for prop in new_entity.properties:
if len([0 for p in old_entity.properties if p.name == prop.name]) == 0:
newdiff["properties"][prop.name] = {}
Loading