Skip to content
Snippets Groups Projects

Draft: REFACTOR: Treat Entity and Id as equal

Open Henrik tom Wörden requested to merge f-compare-enid into dev
1 file
+ 19
0
Compare changes
  • Side-by-side
  • Inline
+ 19
0
@@ -178,6 +178,16 @@ def getCommitIn(folder):
@@ -178,6 +178,16 @@ def getCommitIn(folder):
return get_commit_in(folder)
return get_commit_in(folder)
 
def entity_and_id(this, that):
 
"""
 
returns true iff exactly one of this and that is an Entity with an ID and the other is an
 
integer
 
"""
 
return (
 
(isinstance(this, Entity) and this.id is not None and isinstance(that, int))
 
or (isinstance(this, int) and isinstance(that, Entity) and this.id is not None))
 
 
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.
"""Compare two entites.
@@ -279,6 +289,15 @@ def compare_entities(old_entity: Entity, new_entity: Entity, compare_referenced_
@@ -279,6 +289,15 @@ def compare_entities(old_entity: Entity, new_entity: Entity, compare_referenced_
if (prop.value != matching[0].value):
if (prop.value != matching[0].value):
# basic comparison of value objects says they are different
# basic comparison of value objects says they are different
same_value = False
same_value = False
 
 
# one Entity with ID and one int?
 
if (sufficient_id and ):
 
if ((isinstance(matching[0].value, int)
 
and prop.value.id == matching[0].value)
 
or (isinstance(prop.value, int)
 
and prop.value == matching[0].value.id)):
 
same_value = True
 
if compare_referenced_records:
if compare_referenced_records:
# scalar reference
# scalar reference
if isinstance(prop.value, Entity) and isinstance(matching[0].value, Entity):
if isinstance(prop.value, Entity) and isinstance(matching[0].value, Entity):
Loading