From 7c210f99073829f14c7cdef3f054fbc9fbbe22e1 Mon Sep 17 00:00:00 2001 From: abidaliamanat9 Date: Sun, 30 Aug 2026 15:12:09 +0500 Subject: [PATCH 1/2] Document that read_only_fields ignores explicitly declared fields. Refs #3460 --- docs/api-guide/serializers.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 2ec98f01bf..d17ae8dcc7 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -559,6 +559,8 @@ This option should be a list or tuple of field names, and is declared as follows Model fields which have `editable=False` set, and `AutoField` fields will be set to read-only by default, and do not need to be added to the `read_only_fields` option. +Please keep in mind that, if the field has already been explicitly declared on the serializer class, then the `read_only_fields` option will be ignored. Set `read_only=True` on the field itself instead. + !!! note There is a special-case where a read-only field is part of a `unique_together` constraint at the model level. In this case the field is required by the serializer class in order to validate the constraint, but should also not be editable by the user. @@ -591,7 +593,7 @@ This option is a dictionary, mapping field names to a dictionary of keyword argu user.save() return user -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. +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`. ### Relational fields From 3c97b39d68abe79030b2db78213baab5d4f69b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asif=20Saif=20Uddin=20=7B=22Auvi=22=3A=22=E0=A6=85?= =?UTF-8?q?=E0=A6=AD=E0=A6=BF=22=7D?= Date: Mon, 31 Aug 2026 10:32:26 +0600 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- docs/api-guide/serializers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index d17ae8dcc7..7259cb6676 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -559,7 +559,7 @@ This option should be a list or tuple of field names, and is declared as follows Model fields which have `editable=False` set, and `AutoField` fields will be set to read-only by default, and do not need to be added to the `read_only_fields` option. -Please keep in mind that, if the field has already been explicitly declared on the serializer class, then the `read_only_fields` option will be ignored. Set `read_only=True` on the field itself instead. +Please keep in mind that, if a field has already been explicitly declared on the serializer class (or a parent class), then the `read_only_fields` option will not apply to that field. Set `read_only=True` on the field itself instead. !!! note There is a special-case where a read-only field is part of a `unique_together` constraint at the model level. In this case the field is required by the serializer class in order to validate the constraint, but should also not be editable by the user.