From d16bdc4a772110bc737047ab92501fbe4a6a99ca Mon Sep 17 00:00:00 2001 From: "khassan.abdallakh" Date: Wed, 12 Mar 2025 15:39:28 +0300 Subject: [PATCH] Implement a check to ensure the sequence length is greater than 0 before adding the field to the embedded dictionary --- fastapi_hypermodel/hal/hal_hypermodel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastapi_hypermodel/hal/hal_hypermodel.py b/fastapi_hypermodel/hal/hal_hypermodel.py index 9e0ae31..8c365dd 100644 --- a/fastapi_hypermodel/hal/hal_hypermodel.py +++ b/fastapi_hypermodel/hal/hal_hypermodel.py @@ -220,7 +220,7 @@ def add_hypermodels_to_embedded(self: Self) -> Self: embedded: Dict[str, Union[Self, Sequence[Self]]] = {} for name, field in self: value: Sequence[Union[Any, Self]] = ( - field if isinstance(field, Sequence) else [field] + field if isinstance(field, Sequence) and len(field) else [field] ) if not all(isinstance(element, HALHyperModel) for element in value):