Skip to content

Commit

Permalink
[#243] fix nested expand values
Browse files Browse the repository at this point in the history
  • Loading branch information
SonnyBA committed Nov 20, 2024
1 parent ec47146 commit 03821ea
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/openklant/components/utils/expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,19 @@ def display_children(self) -> dict:
"""
results = {}
for child in self._children:
# TODO: rewrite display function?
child_result = child.display() if child.value else None
child_result = child.display()

if child.many:
child_results = results.setdefault(child.label, [])

if child_result:
if child_result is not None:
child_results.append(child_result)
else:
results[child.label] = child_result
return results

def display(self) -> dict:
data = self.value.copy()
def display(self) -> Optional[dict]:
data = self.value.copy() if self.value is not None else None
if self._children:
data[EXPAND_KEY] = self.display_children()
return data
Expand Down Expand Up @@ -254,6 +253,8 @@ def _field_inclusions(
True if hasattr(field, "child_relation") else getattr(field, "many", False)
)

obj: Optional[models.Model] = None

for obj in self._some_related_field_inclusions(
new_path, field, instance, inclusion_serializer
):
Expand All @@ -269,7 +270,7 @@ def _field_inclusions(
yield entry
else:
if new_path in self.allowed_paths:
yield None, inclusion_serializer, instance, new_path, many
yield obj, inclusion_serializer, instance, new_path, many

def _some_related_field_inclusions(
self,
Expand Down

0 comments on commit 03821ea

Please sign in to comment.