From 12f5d01b8db787a5f1d5c13f0a844bf842077ca4 Mon Sep 17 00:00:00 2001 From: semio Date: Wed, 13 Nov 2019 16:36:25 +0800 Subject: [PATCH] more validation for entity and more error messages related issue #120 --- ddf_utils/model/ddf.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ddf_utils/model/ddf.py b/ddf_utils/model/ddf.py index 865bb9c..2cf1807 100644 --- a/ddf_utils/model/ddf.py +++ b/ddf_utils/model/ddf.py @@ -80,7 +80,13 @@ class EntityDomain: @entities.validator def _check_entities_identity(self, attribute, value): + if len(value) == 0: # do nothing if there are no entities yet. + return entities_id_list = self.entity_ids + entities_domain_set = set([x.domain for x in self.entities]) + if len(entities_domain_set) > 1 or self.id not in entities_domain_set: + other_domains = list(entities_domain_set - set([self.id])) + raise ValueError(f"there are entities with different domain: {other_domains}. Expected domain: {self.id}") counter = Counter(entities_id_list) error = False for k, v in counter.items(): @@ -146,6 +152,7 @@ def to_dict(self, eset=None): def add_entity(self, ent: Entity): if ent.domain != self.id: + logger.critical(f"trying to add Entity(id={ent.id}, domain={ent.domain}) to {self.id} domain") raise ValueError('domain name mismatch for the entity object and domain object!') for existing_ent in self.entities: if ent.id == existing_ent.id: