Skip to content

Commit

Permalink
#145: Deal with attributes that have MANY relationships
Browse files Browse the repository at this point in the history
- This code needs to be recursed over, since multiple 'levels' of mandatory MANY relationships don't happen currently and this results in a database related error
  • Loading branch information
MRichards99 committed Oct 8, 2020
1 parent 5eed66e commit 85860ff
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion common/icat/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ICATValidationError,
ICATInternalError,
ICATObjectExistsError,
ICATNoObjectError,
)
from common.exceptions import (
AuthenticationError,
Expand Down Expand Up @@ -867,7 +868,15 @@ def create_entities(client, table_name, data):

else:
# This means the attribute has a relationship with another object
related_object = client.get(entity_info.type, value)
log.debug(f"Entity Info: {entity_info}")
try:
related_object = client.get(entity_info.type, value)
except ICATNoObjectError as e:
raise BadRequestError(e)
# TODO - Recurse over related_object and get included entities from
# them
if entity_info.relType.lower() == "many":
related_object = [related_object]
setattr(new_entity, attribute_name, related_object)

except ValueError as e:
Expand Down

0 comments on commit 85860ff

Please sign in to comment.