Skip to content
Snippets Groups Projects
Commit 049776f4 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

ENH: Allow internal properties in the extern keyword of yaml models

parent 78c738ed
No related branches found
No related tags found
2 merge requests!39Release 0.4.0,!37F extern name
...@@ -33,6 +33,12 @@ import caosdb as db ...@@ -33,6 +33,12 @@ import caosdb as db
from caosdb.apiutils import compare_entities, describe_diff from caosdb.apiutils import compare_entities, describe_diff
CAOSDB_INTERNAL_PROPERTIES = [
"name",
"unit",
]
class DataModel(dict): class DataModel(dict):
"""Provides tools for managing a data model. """Provides tools for managing a data model.
...@@ -129,8 +135,13 @@ class DataModel(dict): ...@@ -129,8 +135,13 @@ class DataModel(dict):
any_change = False any_change = False
for ent in existing_entities: for ent in existing_entities:
q = db.Query("FIND * with id={}".format(ent.id)) if ent.name in CAOSDB_INTERNAL_PROPERTIES:
ref = q.execute(unique=True) # Workaround for the usage of internal properties like name
# in via the extern keyword:
ref = db.Property(name=ent.name).retrieve()
else:
q = db.Query("FIND * with id={}".format(ent.id))
ref = q.execute(unique=True)
diff = (describe_diff(*compare_entities(ent, ref diff = (describe_diff(*compare_entities(ent, ref
), name=ent.name)) ), name=ent.name))
......
...@@ -22,7 +22,7 @@ import sys ...@@ -22,7 +22,7 @@ import sys
import caosdb as db import caosdb as db
import yaml import yaml
from .data_model import DataModel from .data_model import CAOSDB_INTERNAL_PROPERTIES, DataModel
# Keywords which are allowed in data model descriptions. # Keywords which are allowed in data model descriptions.
KEYWORDS = ["parent", # deprecated, use inherit_from_* instead: KEYWORDS = ["parent", # deprecated, use inherit_from_* instead:
...@@ -186,6 +186,9 @@ class Parser(object): ...@@ -186,6 +186,9 @@ class Parser(object):
ymlmodel["extern"] = [] ymlmodel["extern"] = []
for name in ymlmodel["extern"]: for name in ymlmodel["extern"]:
if name in CAOSDB_INTERNAL_PROPERTIES:
self.model[name] = db.Property(name=name).retrieve()
continue
for role in ("Property", "RecordType", "Record", "File"): for role in ("Property", "RecordType", "Record", "File"):
if db.execute_query("COUNT {} {}".format(role, name)) > 0: if db.execute_query("COUNT {} {}".format(role, name)) > 0:
self.model[name] = db.execute_query( self.model[name] = db.execute_query(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment