diff --git a/apis_ontology/importers.py b/apis_ontology/importers.py index 5b03765..a91d306 100644 --- a/apis_ontology/importers.py +++ b/apis_ontology/importers.py @@ -18,10 +18,14 @@ def create_instance(self): if sa.count() == 1: return sa.first().root_object elif sa.count() > 1: - raise IntegrityError( - f"Multiple objects found for sameAs URIs {data['sames']}. " - f"This indicates a data integrity problem as these URIs should be unique." - ) + root_set = set([s.root_object for s in sa]) + if len(root_set) > 1: + raise IntegrityError( + f"Multiple objects found for sameAs URIs {data['sames']}. " + f"This indicates a data integrity problem as these URIs should be unique." + ) + else: + return sa.first().root_object modelfields = [field.name for field in self.model._meta.fields] data_croped = {key: data[key] for key in data if key in modelfields} subj = self.model.objects.create(**data_croped) @@ -39,10 +43,10 @@ def create_instance(self): if key in data: related_obj = create_object_from_uri(data[key], RelatedModel) RelationType.objects.create(subj=subj, obj=related_obj) - except: # noqa: E722 + except Exception as e: # noqa: E722 subj.delete() raise ImproperlyConfigured( - f"Error in creating related Objects for {self.model.__class__.__name__}" + f"Error in creating related Objects for {self.model}: {e}" ) return subj