Skip to content

Commit

Permalink
fix: wrong check on many objects to URI
Browse files Browse the repository at this point in the history
  • Loading branch information
sennierer committed Dec 13, 2024
1 parent c01aa8a commit ac39069
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions apis_ontology/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit ac39069

Please sign in to comment.