Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
1b3f81a8
Commit
1b3f81a8
authored
5 months ago
by
I. Nüske
Browse files
Options
Downloads
Patches
Plain Diff
MNT: Fix entity_name_id_equivalency recursion
parent
f8ad701c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!159
Release 0.16.o
,
!155
Review filter lists and compare_entities
Pipeline
#56987
passed with warnings
5 months ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/linkahead/apiutils.py
+15
-8
15 additions, 8 deletions
src/linkahead/apiutils.py
with
15 additions
and
8 deletions
src/linkahead/apiutils.py
+
15
−
8
View file @
1b3f81a8
...
@@ -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
"
]:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment