fastapi-hypermodel icon indicating copy to clipboard operation
fastapi-hypermodel copied to clipboard

Fix empty sequence adding to embedded bug

Open exorevan opened this issue 11 months ago • 3 comments

Implement a check to ensure the sequence length is greater than 0 before adding the field to the embedded dictionary.

For example: if field value is '' then it goes to embedded dict from the model

exorevan avatar Mar 12 '25 12:03 exorevan

Could you provide a minimal example where this is a problem?

ELC avatar Mar 12 '25 22:03 ELC

Of course:

>>> import fastapi_hypermodel
>>> class Process(fastapi_hypermodel.HALHyperModel):
...     number: int
...     message: str | None
... 
>>> process_dict = {"number": 0, "message": ""}
>>> process_hal = Process(**process_dict)
>>> process_hal
Process(links=None, embedded={'message': ''}, number=0)

exorevan avatar Mar 13 '25 08:03 exorevan

@ELC are you happy for this one to be merged?

jtc42 avatar Apr 06 '25 15:04 jtc42