firedantic icon indicating copy to clipboard operation
firedantic copied to clipboard

Support "omit empty"

Open lietu opened this issue 4 years ago • 2 comments

Golang firestore library supports the ability to tag fields as omitempty meaning they will not get stored in the DB when not set. This could be done via e.g. combining Optional with a Config option like

class Model(AsyncModel):
  field: Optional[str]
  another: Optional[List[int]]
  # ...
  
  class Config:
    omitempty = "*"
    # or
    omitempty = ["field", "another"]

lietu avatar Aug 21 '21 09:08 lietu

Alternatively e.g. by extending Field() or similar from pydantic

lietu avatar Aug 21 '21 09:08 lietu

Pydantic dict() and json(), or the corresponding model_dump() in v2, support the param:

exclude_unset: Whether to exclude fields that are unset or None from the output.

So maybe Firedantic save() could have it similarily easily.

But I agree that model conf for it would be nice.

antont avatar Oct 04 '23 05:10 antont