From 887d98a4940604c8a6197756a9489f19b7ab2e4c Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Fri, 28 Aug 2020 13:45:59 +0000 Subject: [PATCH] f-check-datamodel -> dev --- CHANGELOG.md | 2 ++ src/caosadvancedtools/serverside/helper.py | 29 ++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d7f77a9..9ef66957 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed ### +* `caosadvancedtools.serverside.helper.init_data_model` also checks the role + and data type of entities. * The `caosadvancedtools.table_importer.date_converter` now actually returns `datetime.date` instance. A new `caosadvancedtools.table_importer.datetime_converter` replaces the old diff --git a/src/caosadvancedtools/serverside/helper.py b/src/caosadvancedtools/serverside/helper.py index 5b3adba3..f2dd96da 100644 --- a/src/caosadvancedtools/serverside/helper.py +++ b/src/caosadvancedtools/serverside/helper.py @@ -147,13 +147,13 @@ def print_error(text): class DataModelError(RuntimeError): """DataModelError indicates that the server-side script cannot work as - intended due to missing datat model entities or an otherwise incompatible + intended due to missing data model entities or an otherwise incompatible data model.""" - def __init__(self, rt): + def __init__(self, rt, info=""): super().__init__( "This script expects certain RecordTypes and Properties to exist " - "in the data model. There is a problem with {} .".format(rt)) + "in the data model. There is a problem with {}. {}".format(rt, info)) def recordtype_is_child_of(rt, parent): @@ -183,7 +183,11 @@ def recordtype_is_child_of(rt, parent): def init_data_model(entities): - """Return True if all entities exist. + """Return True iff all entities exist and their role and possibly their + data type is correct. + + This implementation follows a fail-fast approach. The first entity with + problems will raise an exception. Parameters ---------- @@ -194,18 +198,29 @@ def init_data_model(entities): Raises ------ DataModelError - If any entity in `entities` does not exists. + If any entity in `entities` does not exist or the role or data type is + not matching. Returns ------- bool - True if all entities exist. + True if all entities exist and their role and data type are matching. """ try: for e in entities: + local_datatype = e.datatype + local_role = e.role e.retrieve() + if local_datatype is not None and local_datatype != e.datatype: + info = ("The remote entity has a {} data type while it should " + "have a {}.".format(e.datatype, local_datatype)) + raise DataModelError(e.name, info) + if local_role is not None and local_role != e.role: + info = ("The remote entity has is a {} while it should " + "be a {}.".format(e.role, local_role)) + raise DataModelError(e.name, info) except db.exceptions.EntityDoesNotExistError: - raise DataModelError(e.name) + raise DataModelError(e.name, "This entity does not exist.") return True -- GitLab