Skip to content
Snippets Groups Projects
Commit ef34db53 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

FIX: add datatype, unit and description to properties that are part of Records

parent cb4bc1ed
No related branches found
No related tags found
2 merge requests!128MNT: Added a warning when column metadata is not configured, and a better...,!115add datatype, unit and description to properties that are part of Records
Pipeline #56221 failed
...@@ -149,6 +149,7 @@ class DataModel(dict): ...@@ -149,6 +149,7 @@ class DataModel(dict):
), name=ent.name)) ), name=ent.name))
if diff != "": if diff != "":
breakpoint()
if verbose: if verbose:
print(diff) print(diff)
any_change = True any_change = True
......
...@@ -341,6 +341,38 @@ debug : bool, optional ...@@ -341,6 +341,38 @@ debug : bool, optional
f"invalid keyword in line {entity['__line__']}:", 1) f"invalid keyword in line {entity['__line__']}:", 1)
raise ValueError(err_str, *err.args[1:]) from err raise ValueError(err_str, *err.args[1:]) from err
# Update properties that are part of record types:
# e.g. add their datatypes, units etc..
# Otherwise comparison of existing models and the parsed model become difficult.
for name, ent in self.model.items():
if not isinstance(ent, db.RecordType):
continue
props = ent.get_properties()
for prop in props:
if prop.name in self.model:
model_prop = self.model[prop.name]
# The information must be missing, we don't want to overwrite it accidentally:
if prop.datatype is not None and prop.datatype != model_prop.datatype:
# breakpoint()
raise RuntimeError("datatype must not be set, here. This is probably a bug.")
if prop.unit is not None and prop.unit != model_prop.unit:
# continue
raise RuntimeError("unit must not be set, here. This is probably a bug.")
if prop.description is not None and prop.description != model_prop.description:
# continue
raise RuntimeError("description must not be set, here. This is probably a bug.")
# If this property has a more detailed definition in the model,
# copy over the information:
if isinstance(model_prop, db.RecordType):
# in this case the datatype equals the name of the record type:
prop.datatype = prop.name
else:
prop.datatype = model_prop.datatype
prop.unit = model_prop.unit
prop.description = model_prop.description
return DataModel(self.model.values()) return DataModel(self.model.values())
@staticmethod @staticmethod
...@@ -470,6 +502,7 @@ debug : bool, optional ...@@ -470,6 +502,7 @@ debug : bool, optional
""" """
for n, e in props.items(): for n, e in props.items():
if n in KEYWORDS: if n in KEYWORDS:
if n in KEYWORDS_IGNORED: if n in KEYWORDS_IGNORED:
continue continue
...@@ -543,6 +576,13 @@ debug : bool, optional ...@@ -543,6 +576,13 @@ debug : bool, optional
if name in self.treated: if name in self.treated:
raise TwiceDefinedException(name) raise TwiceDefinedException(name)
# for reducing a little bit of code duplication:
importance_dict = {
"recommended_properties": db.RECOMMENDED,
"obligatory_properties": db.OBLIGATORY,
"suggested_properties": db.SUGGESTED
}
for prop_name, prop in definition.items(): for prop_name, prop in definition.items():
if prop_name == "__line__": if prop_name == "__line__":
continue continue
...@@ -558,26 +598,14 @@ debug : bool, optional ...@@ -558,26 +598,14 @@ debug : bool, optional
# Handled above # Handled above
continue continue
elif prop_name == "recommended_properties": elif prop_name in importance_dict:
self._add_to_recordtype( for imp_name, imp_val in importance_dict.items():
name, prop, importance=db.RECOMMENDED) if prop_name == imp_name:
self._add_to_recordtype(
for n, e in prop.items(): name, prop, importance=imp_val)
self._treat_entity(n, e)
elif prop_name == "obligatory_properties":
self._add_to_recordtype(
name, prop, importance=db.OBLIGATORY)
for n, e in prop.items():
self._treat_entity(n, e)
elif prop_name == "suggested_properties":
self._add_to_recordtype(
name, prop, importance=db.SUGGESTED)
for n, e in prop.items(): for n, e in prop.items():
self._treat_entity(n, e) self._treat_entity(n, e)
# datatype is already set # datatype is already set
elif prop_name == "datatype": elif prop_name == "datatype":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment