Skip to content

Document that read_only_fields ignores explicitly declared fields - #10028

Merged
browniebroke merged 2 commits into
encode:mainfrom
abidaliamanat9:docs-read-only-fields-explicit-declaration
Sep 1, 2026
Merged

Document that read_only_fields ignores explicitly declared fields#10028
browniebroke merged 2 commits into
encode:mainfrom
abidaliamanat9:docs-read-only-fields-explicit-declaration

Conversation

@abidaliamanat9

@abidaliamanat9 abidaliamanat9 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Description

refs #3460

read_only_fields is implemented by merging into Meta.extra_kwargs, and explicitly declared fields skip that path. The extra_kwargs docs already mention the ignore behavior; the read_only_fields section did not.

This adds the same warning next to read_only_fields, and a one-line cross-reference under extra_kwargs.

Maintainers previously asked for this note rather than changing the API:

We could take a Note to the serialiser docs below the Additional keyword arguments section saying that both these attributes are superseded by an explicit declaration.

#3460 (comment)

I also commented on the issue:

#3460 (comment)

@abidaliamanat9 abidaliamanat9 changed the title Fixes #3460 Document that read_only_fields ignores explicitly declared fields Aug 30, 2026
@auvipy
auvipy requested review from auvipy and a lite review from Copilot August 31, 2026 04:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the DRF serializer documentation to explicitly call out that Meta.read_only_fields does not override attributes for fields that are explicitly declared on the serializer (because the shortcut is applied via extra_kwargs, which declared fields bypass).

Changes:

  • Adds an explicit warning under the read_only_fields documentation explaining the ignore behavior for explicitly declared fields.
  • Adds a short cross-reference in the extra_kwargs section noting that the same rule applies to read_only_fields.
Suppressed comments (1)

docs/api-guide/serializers.md:596

  • Similar to the read_only_fields note above, this sentence could be interpreted as extra_kwargs being ignored entirely rather than ignored for the explicitly declared field. Clarifying the scope (and that inherited declared fields also bypass extra_kwargs) would reduce confusion.
Please keep in mind that, if the field has already been explicitly declared on the serializer class, then the `extra_kwargs` option will be ignored. The same is true of `read_only_fields`, which is implemented using `extra_kwargs`.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/api-guide/serializers.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@browniebroke browniebroke changed the title Document that read_only_fields ignores explicitly declared fields Document that read_only_fields ignores explicitly declared fields Sep 1, 2026
@browniebroke
browniebroke merged commit 179e8a5 into encode:main Sep 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants