diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d7f77a931cd917cc976b9af29f3e88e9dd2a53d..9ef6695787f2d43df6636eba6890084882f1228c 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 5b3adba395b9d3a1d2d3bc81fa0f46c1d019c9c6..f2dd96da18a0cbd5f3864b6a3d6b2a6a12fa3cc6 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