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

docs: mention id field in 1-abstract-dto.rst #3803

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@


class User(Base):
# `Base` defines `id` field as:
# id: Mapped[UUID] = mapped_column(default=uuid4, primary_key=True)
name: Mapped[str]
password: Mapped[str] = mapped_column(info=dto_field("private"))
created_at: Mapped[datetime] = mapped_column(info=dto_field("read-only"))
Expand All @@ -20,6 +22,9 @@ class User(Base):

@post("/users", dto=UserDTO, sync_to_thread=False)
def create_user(data: User) -> User:
# even though the client did not send the id field,
# since it is a primary key it is autogenerated
assert "id" in vars(data)
# even though the client sent the password and created_at field, it is not in the data object
assert "password" not in vars(data)
assert "created_at" not in vars(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class User(Base):
# `Base` defines `id` field as:
# id: Mapped[UUID] = mapped_column(default=uuid4, primary_key=True)
name: Mapped[str]
password: Mapped[str]
created_at: Mapped[datetime]
Expand Down
2 changes: 2 additions & 0 deletions docs/usage/dto/1-abstract-dto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Fields marked as ``"private"`` or ``"read-only"`` will not be parsed from client
:emphasize-lines: 6,14,15
:linenos:

Note that ``id`` field is handled specially, since it is a primary key.

.. note:

The procedure for "marking" a model field will vary depending on the library. For example,
Expand Down
Loading