Make all fields optional in an update model and apply only the fields the client actually sent using model_dump(exclude_unset=True); otherwise defaults would overwrite stored values with None.
class ItemUpdate(BaseModel):
name: str | None = None
price: float | None = None
@app.patch("/items/{item_id}", response_model=Item)
def patch_item(item_id: int, update: ItemUpdate):
stored = items[item_id] # an Item model
changes = update.model_dump(exclude_unset=True) # only fields the client sent
items[item_id] = stored.model_copy(update=changes)
return items[item_id]