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

FIX(yaml-model-parser): add datatype and other missing attributes to...

FIX(yaml-model-parser): add datatype and other missing attributes to properties belonging to record types in data model
parent d753df87
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
......@@ -37,18 +37,17 @@ to be a list with the names. Here, NO NEW entities can be defined.
"""
import argparse
import json
import jsonref
import re
import sys
import yaml
from typing import List, Optional
from warnings import warn
import jsonref
import jsonschema
import linkahead as db
import yaml
from linkahead.common.datatype import get_list_datatype
from .data_model import LINKAHEAD_INTERNAL_PROPERTIES, DataModel
# Keywords which are allowed in data model descriptions.
......@@ -341,38 +340,37 @@ debug : bool, optional
f"invalid keyword in line {entity['__line__']}:", 1)
raise ValueError(err_str, *err.args[1:]) from err
# TODO: functionality commented out, to be able to test failing test first.
# 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
# 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())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment