Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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-advanced-user-tools
Commits
526b634d
Verified
Commit
526b634d
authored
1 year ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
FIX: get_deep: multiple use of properties
parent
987ab1b4
No related branches found
No related tags found
2 merge requests
!89
ENH: JsonSchemaExporter accepts do_not_create parameter.
,
!88
jsex / yaml parser
Pipeline
#44121
passed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosadvancedtools/models/data_model.py
+11
-4
11 additions, 4 deletions
src/caosadvancedtools/models/data_model.py
unittests/test_data_model.py
+18
-0
18 additions, 0 deletions
unittests/test_data_model.py
with
29 additions
and
4 deletions
src/caosadvancedtools/models/data_model.py
+
11
−
4
View file @
526b634d
...
...
@@ -31,7 +31,7 @@ from typing import List
import
linkahead
as
db
import
linkahead.common.models
as
models
from
linkahead.apiutils
import
compare_entities
,
describe_diff
from
linkahead.apiutils
import
compare_entities
,
describe_diff
,
merge_entities
CAOSDB_INTERNAL_PROPERTIES
=
[
...
...
@@ -264,7 +264,7 @@ class DataModel(dict):
return
list
(
all_ents
.
values
())
def
get_deep
(
self
,
name
:
str
,
visited_props
:
se
t
=
None
,
visited_parents
:
set
=
None
):
def
get_deep
(
self
,
name
:
str
,
visited_props
:
dic
t
=
None
,
visited_parents
:
set
=
None
):
"""
Attempt to resolve references for the given ``name``.
The returned entity has all the properties it inherits from its ancestry and all properties
...
...
@@ -279,7 +279,7 @@ class DataModel(dict):
if
not
entity
:
return
entity
if
not
visited_props
:
visited_props
=
set
()
visited_props
=
{}
if
not
visited_parents
:
visited_parents
=
set
()
...
...
@@ -309,8 +309,14 @@ class DataModel(dict):
for
prop
in
list
(
entity
.
get_properties
()):
# Make a change-resistant list copy.
if
prop
.
name
in
visited_props
:
if
visited_props
[
prop
.
name
]:
deep_prop
=
visited_props
[
prop
.
name
]
merge_entities
(
prop
,
deep_prop
)
prop
.
datatype
=
deep_prop
.
datatype
prop
.
value
=
deep_prop
.
value
prop
.
unit
=
deep_prop
.
unit
continue
visited_props
.
add
(
prop
.
name
)
visited_props
[
prop
.
name
]
=
None
if
prop
.
name
in
self
:
deep_prop
=
self
.
get_deep
(
prop
.
name
,
visited_props
=
visited_props
,
visited_parents
=
visited_parents
)
...
...
@@ -322,6 +328,7 @@ class DataModel(dict):
linked_prop
.
datatype
=
deep_prop
if
deep_prop
.
description
:
linked_prop
.
description
=
deep_prop
.
description
visited_props
[
prop
.
name
]
=
deep_prop
else
:
print
(
f
"
Referenced property
\"
{
prop
.
name
}
\"
not found in data model.
"
)
...
...
This diff is collapsed.
Click to expand it.
unittests/test_data_model.py
+
18
−
0
View file @
526b634d
...
...
@@ -62,3 +62,21 @@ RT1:
rt1_deep
=
model_unresolved
.
get_deep
(
"
RT1
"
)
assert
rt1_deep
==
rt1_unresolved
assert
rt1_deep
is
rt1_unresolved
model_double_property
=
"""
p1:
description: Hello world
datatype: TEXT
RT1:
recommended_properties:
p1:
RT2:
recommended_properties:
RT1:
p1:
"""
model_unresolved
=
parse_model_from_string
(
model_double_property
)
rt2_deep
=
model_unresolved
.
get_deep
(
"
RT2
"
)
p1
=
rt2_deep
.
get_property
(
"
p1
"
)
assert
p1
.
datatype
==
"
TEXT
"
assert
p1
.
description
==
"
Hello world
"
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