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
15ac87c5
Commit
15ac87c5
authored
2 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Add `empty_diff` function to apiutils
parent
d38254bd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!79
Release 0.10.0
,
!72
F fix merge entity conflicts
Pipeline
#29678
failed
2 years 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/caosdb/apiutils.py
+41
-3
41 additions, 3 deletions
src/caosdb/apiutils.py
with
41 additions
and
3 deletions
src/caosdb/apiutils.py
+
41
−
3
View file @
15ac87c5
...
...
@@ -188,9 +188,8 @@ def getCommitIn(folder):
return
t
.
readline
().
strip
()
def
compare_entities
(
old_entity
:
Entity
,
new_entity
:
Entity
):
"""
Compare two entites.
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
entity, the second index belongs to additional information for new entity.
...
...
@@ -204,6 +203,20 @@ def compare_entities(old_entity: Entity, new_entity: Entity):
- ... 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.
If `compare_referenced_records` is `True`, also referenced entities will be
compared using this function, but with `compare_referenced_records = False`
to prevent infinite recursion in case of circular references.
Parameters
----------
old_entity, new_entity : Entity
Entities to be compared
compare_referenced_records : bool, optional
Whether to compare referenced records in case of both, `old_entity` and
`new_entity`, have the same reference properties and both have a Record
object as value.
"""
olddiff
:
Dict
[
str
,
Any
]
=
{
"
properties
"
:
{},
"
parents
"
:
[]}
newdiff
:
Dict
[
str
,
Any
]
=
{
"
properties
"
:
{},
"
parents
"
:
[]}
...
...
@@ -300,6 +313,31 @@ def compare_entities(old_entity: Entity, new_entity: Entity):
return
(
olddiff
,
newdiff
)
def
empty_diff
(
old_entity
:
Entity
,
new_entity
:
Entity
,
compare_referenced_records
:
bool
=
False
):
"""
Check whether the `compare_entities` found any differences between
old_entity and new_entity.
Parameters
----------
old_entity, new_entity : Entity
Entities to be compared
compare_referenced_records : bool, optional
Whether to compare referenced records in case of both, `old_entity` and
`new_entity`, have the same reference properties and both have a Record
object as value.
"""
olddiff
,
newdiff
=
compare_entities
(
old_entity
,
new_entity
,
compare_referenced_records
)
for
diff
in
[
olddiff
,
newdiff
]:
for
key
in
diff
:
if
len
(
diff
[
key
])
>
0
:
# There is a difference somewhere in the diff
return
False
# all elements of the two diffs were empty
return
True
def
merge_entities
(
entity_a
:
Entity
,
entity_b
:
Entity
):
"""
Merge entity_b into entity_a such that they have the same parents and properties.
...
...
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