Skip to content

Commit

Permalink
fix: do not attempt to create related entities if not included #387
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Nov 16, 2022
1 parent 57edaaa commit 819e7a1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions datagateway_api/src/search_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ def from_icat(cls, icat_data, required_related_fields): # noqa: B902, N805
# we have to get hold of its class definition and call its `from_icat`
# method to create an instance of itself with the ICAT data provided.
# Doing this allows for recursion.

if entity_field_alias not in [
required_related_field.split(".")[0]
for required_related_field in required_related_fields
]:
# Before proceeding, check if the related entity really needs to be created.
# Do not attempt to create the related entity if ICAT data for it is available
# but the entity has not been specified to be included. In such cases, the ICAT
# data is likely available because the data for another entity field is
# retrieved via that ICAT entity. We do not want to return data for related
# entities unless explicitly specified to be included by the user.
continue

data = (
[field_value] if not isinstance(field_value, list) else field_value
)
Expand Down

0 comments on commit 819e7a1

Please sign in to comment.