Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial updates and strict validation to the CRUD tutorial #877

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/docs/tutorial/other/crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ employee.department_id = payload.department_id
employee.birthdate = payload.birthdate
```

**Partial updates**

To allow the user to make partial updates, use `payload.dict(exclude_unset=True).items()`. This ensures that only the specified fields get updated.

**Enforcing strict field validation**

By default, any provided fields that don't exist in the schema will be silently ignored. To raise an error for these invalid fields, you can set `extra = "forbid"` in the schema's Config class. For example:

```Python hl_lines="4 5"
class EmployeeIn(Schema):
# your fields here...

class Config:
extra = "forbid"
```

## Delete

Expand Down