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
3787cd88
Commit
3787cd88
authored
2 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Implement force merge
parent
d52be656
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!79
Release 0.10.0
,
!74
F force merge
Pipeline
#29856
passed
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
+11
-1
11 additions, 1 deletion
src/caosdb/apiutils.py
with
11 additions
and
1 deletion
src/caosdb/apiutils.py
+
11
−
1
View file @
3787cd88
...
...
@@ -361,7 +361,7 @@ def empty_diff(old_entity: Entity, new_entity: Entity, compare_referenced_record
return
True
def
merge_entities
(
entity_a
:
Entity
,
entity_b
:
Entity
,
merge_references_with_empty_diffs
=
True
):
def
merge_entities
(
entity_a
:
Entity
,
entity_b
:
Entity
,
merge_references_with_empty_diffs
=
True
,
force
=
False
):
"""
Merge entity_b into entity_a such that they have the same parents and properties.
...
...
@@ -385,6 +385,10 @@ def merge_entities(entity_a: Entity, entity_b: Entity, merge_references_with_emp
record(s) that may be different Python objects but have empty diffs. If
set to `False` a merge conflict will be raised in this case
instead. Default is True.
force : bool, optional
If True, in case `entity_a` and `entity_b` have the same properties, the
values of `entity_b` are sued in the merge. If `False`, a RuntimeError is
raised instead. Default is False.
Returns
-------
...
...
@@ -421,6 +425,9 @@ def merge_entities(entity_a: Entity, entity_b: Entity, merge_references_with_emp
if
(
diff_r1
[
"
properties
"
][
key
][
attribute
]
is
None
):
setattr
(
entity_a
.
get_property
(
key
),
attribute
,
diff_r2
[
"
properties
"
][
key
][
attribute
])
elif
force
:
setattr
(
entity_a
.
get_property
(
key
),
attribute
,
diff_r2
[
"
properties
"
][
key
][
attribute
])
else
:
raise
RuntimeError
(
f
"
Merge conflict:
\n
Entity a (
{
entity_a
.
id
}
,
{
entity_a
.
name
}
)
"
...
...
@@ -448,6 +455,9 @@ def merge_entities(entity_a: Entity, entity_b: Entity, merge_references_with_emp
if
sa_a
!=
sa_b
:
if
sa_a
is
None
:
setattr
(
entity_a
,
special_attribute
,
sa_b
)
elif
force
:
# force overwrite
setattr
(
entity_a
,
special_attribute
,
sa_b
)
else
:
raise
RuntimeError
(
"
Merge conflict.
"
)
return
entity_a
...
...
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