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
548c04ac
Commit
548c04ac
authored
1 year ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
FIX: added further recursion detections
parent
666d6d41
No related branches found
No related tags found
1 merge request
!109
Detection of cyclic references for high level API
Pipeline
#38495
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
+22
-13
22 additions, 13 deletions
src/caosdb/high_level_api.py
with
22 additions
and
13 deletions
src/caosdb/high_level_api.py
+
22
−
13
View file @
548c04ac
...
...
@@ -265,7 +265,8 @@ class CaosDBPythonEntity(object):
self
.
_version
=
val
def
_set_property_from_entity
(
self
,
ent
:
db
.
Entity
,
importance
:
str
,
references
:
Optional
[
db
.
Container
]):
references
:
Optional
[
db
.
Container
],
visited
:
Dict
[
int
,
"
CaosDBPythonEntity
"
]):
"""
Set a new property using an entity from the normal python API.
...
...
@@ -280,7 +281,7 @@ class CaosDBPythonEntity(object):
raise
RuntimeError
(
"
Multiproperty not implemented yet.
"
)
val
=
self
.
_type_converted_value
(
ent
.
value
,
ent
.
datatype
,
references
)
references
,
visited
)
self
.
set_property
(
ent
.
name
,
val
,
...
...
@@ -382,7 +383,8 @@ class CaosDBPythonEntity(object):
def
_type_converted_list
(
self
,
val
:
List
,
pr
:
str
,
references
:
Optional
[
db
.
Container
]):
references
:
Optional
[
db
.
Container
],
visited
:
Dict
[
int
,
"
CaosDBPythonEntity
"
]):
"""
Convert a list to a python list of the correct type.
...
...
@@ -396,13 +398,14 @@ class CaosDBPythonEntity(object):
raise
RuntimeError
(
"
Not a list.
"
)
return
[
self
.
_type_converted_value
(
i
,
get_list_datatype
(
pr
),
references
)
for
i
in
val
]
self
.
_type_converted_value
(
i
,
get_list_datatype
(
pr
),
references
,
visited
)
for
i
in
val
]
def
_type_converted_value
(
self
,
val
:
Any
,
pr
:
str
,
references
:
Optional
[
db
.
Container
]):
references
:
Optional
[
db
.
Container
],
visited
:
Dict
[
int
,
"
CaosDBPythonEntity
"
]):
"""
Convert val to the correct type which is indicated by the database
type string in pr.
...
...
@@ -416,9 +419,9 @@ class CaosDBPythonEntity(object):
# this needs to be checked as second case as it is the ONLY
# case which does not depend on pr
# TODO: we might need to pass through the reference container
return
convert_to_python_object
(
val
,
references
)
return
convert_to_python_object
(
val
,
references
,
visited
)
elif
isinstance
(
val
,
list
):
return
self
.
_type_converted_list
(
val
,
pr
,
references
)
return
self
.
_type_converted_list
(
val
,
pr
,
references
,
visited
)
elif
pr
is
None
:
return
val
elif
pr
==
DOUBLE
:
...
...
@@ -436,7 +439,7 @@ class CaosDBPythonEntity(object):
elif
pr
==
DATETIME
:
return
self
.
_parse_datetime
(
val
)
elif
is_list_datatype
(
pr
):
return
self
.
_type_converted_list
(
val
,
pr
,
references
)
return
self
.
_type_converted_list
(
val
,
pr
,
references
,
visited
)
else
:
# Generic references to entities:
return
CaosDBPythonUnresolvedReference
(
val
)
...
...
@@ -843,7 +846,8 @@ def _single_convert_to_python_object(robj: CaosDBPythonEntity,
robj
.
__setattr__
(
base_attribute
,
val
)
for
prop
in
entity
.
properties
:
robj
.
_set_property_from_entity
(
prop
,
entity
.
get_importance
(
prop
),
references
)
robj
.
_set_property_from_entity
(
prop
,
entity
.
get_importance
(
prop
),
references
,
visited
)
for
parent
in
entity
.
parents
:
robj
.
add_parent
(
CaosDBPythonUnresolvedParent
(
id
=
parent
.
id
,
...
...
@@ -955,7 +959,10 @@ def convert_to_python_object(entity: Union[db.Container, db.Entity],
# TODO: recursion problems?
return
_single_convert_to_python_object
(
high_level_type_for_standard_type
(
entity
)(),
entity
,
references
,
visited
)
high_level_type_for_standard_type
(
entity
)(),
entity
,
references
,
visited
)
def
new_high_level_entity
(
entity
:
db
.
RecordType
,
...
...
@@ -993,7 +1000,7 @@ def new_high_level_entity(entity: db.RecordType,
return
convert_to_python_object
(
r
)
def
create_record
(
rtname
:
str
,
name
:
str
=
None
,
**
kwargs
):
def
create_record
(
rtname
:
str
,
name
:
Optional
[
str
]
=
None
,
**
kwargs
):
"""
Create a new record based on the name of a record type. The new record is returned.
...
...
@@ -1032,7 +1039,9 @@ def create_entity_container(record: CaosDBPythonEntity):
return
db
.
Container
().
extend
(
lse
)
def
query
(
query
:
str
,
resolve_references
:
bool
=
True
,
references
:
db
.
Container
=
None
):
def
query
(
query
:
str
,
resolve_references
:
Optional
[
bool
]
=
True
,
references
:
Optional
[
db
.
Container
]
=
None
):
"""
"""
...
...
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