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
666d6d41
Commit
666d6d41
authored
1 year ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
FIX: problems with cyclic references in high level api
parent
968d234f
No related branches found
No related tags found
1 merge request
!109
Detection of cyclic references for high level API
Pipeline
#38488
passed with warnings
1 year 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/high_level_api.py
+23
-7
23 additions, 7 deletions
src/caosdb/high_level_api.py
with
23 additions
and
7 deletions
src/caosdb/high_level_api.py
+
23
−
7
View file @
666d6d41
...
...
@@ -561,8 +561,8 @@ class CaosDBPythonEntity(object):
return
propval
def
resolve_references
(
self
,
deep
:
bool
,
references
:
db
.
Container
,
visited
:
Dict
[
Union
[
str
,
int
],
"
CaosDBPythonEntity
"
]
=
None
):
visited
:
Optional
[
Dict
[
Union
[
str
,
int
],
"
CaosDBPythonEntity
"
]
]
=
None
):
"""
Resolve this entity
'
s references. This affects unresolved properties as well
as unresolved parents.
...
...
@@ -807,7 +807,9 @@ BASE_ATTRIBUTES = (
def
_single_convert_to_python_object
(
robj
:
CaosDBPythonEntity
,
entity
:
db
.
Entity
,
references
:
Optional
[
db
.
Container
]
=
None
):
references
:
Optional
[
db
.
Container
]
=
None
,
visited
:
Optional
[
Dict
[
int
,
"
CaosDBPythonEntity
"
]]
=
None
):
"""
Convert a db.Entity from the standard API to a (previously created)
CaosDBPythonEntity from the high level API.
...
...
@@ -822,6 +824,17 @@ def _single_convert_to_python_object(robj: CaosDBPythonEntity,
Returns the input object robj.
"""
# This parameter is used in the recursion to keep track of already visited
# entites (in order to detect cycles).
if
visited
is
None
:
visited
=
dict
()
if
id
(
entity
)
in
visited
:
return
visited
[
id
(
entity
)]
else
:
visited
[
id
(
entity
)]
=
robj
for
base_attribute
in
BASE_ATTRIBUTES
:
val
=
entity
.
__getattribute__
(
base_attribute
)
if
val
is
not
None
:
...
...
@@ -924,7 +937,9 @@ def convert_to_entity(python_object):
def
convert_to_python_object
(
entity
:
Union
[
db
.
Container
,
db
.
Entity
],
references
:
Optional
[
db
.
Container
]
=
None
):
references
:
Optional
[
db
.
Container
]
=
None
,
visited
:
Optional
[
Dict
[
int
,
"
CaosDBPythonEntity
"
]]
=
None
):
"""
Convert either a container of CaosDB entities or a single CaosDB entity
into the high level representation.
...
...
@@ -936,15 +951,16 @@ def convert_to_python_object(entity: Union[db.Container, db.Entity],
"""
if
isinstance
(
entity
,
db
.
Container
):
# Create a list of objects:
return
[
convert_to_python_object
(
i
,
references
)
for
i
in
entity
]
return
[
convert_to_python_object
(
i
,
references
,
visited
)
for
i
in
entity
]
# TODO: recursion problems?
return
_single_convert_to_python_object
(
high_level_type_for_standard_type
(
entity
)(),
entity
,
references
)
high_level_type_for_standard_type
(
entity
)(),
entity
,
references
,
visited
)
def
new_high_level_entity
(
entity
:
db
.
RecordType
,
importance_level
:
str
,
name
:
str
=
None
):
name
:
Optional
[
str
]
=
None
):
"""
Create an new record in high level format based on a record type in standard format.
...
...
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