How to remove field value using PATCH #675
-
Hi! I am trying to write a PATCH API endpoint that can take a subset of fields and update a product object. Say I have the following schema and endpoint:
If I just want to update the description, I can send this request body: However, if I want to remove the category_id, with a request body like |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
dict method is from pydantic so you can try with for attr, value in payload.dict(exclude_none=True).items():
... |
Beta Was this translation helpful? Give feedback.
-
https://fastapi.tiangolo.com/tutorial/body-updates/#partial-updates-with-patch might also be helpful |
Beta Was this translation helpful? Give feedback.
-
Thanks both! Knowing the dict method was from pydantic was the key unlock here. The parameter I needed was "exclude_unset" (FastAPI documentation contained that as well). Thanks! |
Beta Was this translation helpful? Give feedback.
https://fastapi.tiangolo.com/tutorial/body-updates/#partial-updates-with-patch might also be helpful