Skip to content

Make autogenerated read only fields to be able to be nullable #8536

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jun 28, 2022

Conversation

TheSuperiorStanislav
Copy link
Contributor

@TheSuperiorStanislav TheSuperiorStanislav commented Jun 28, 2022

Description

Move null attr check before return for read-only fields. While as of now it doesn't break anything, it leads to incorrect API schema generation when using drf-spectacular(tfranzel/drf-spectacular#383) or drf-yasg(axnsan12/drf-yasg#310).

Copy link
Member

@tomchristie tomchristie left a comment

Choose a reason for hiding this comment

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

Okay, yup.

I’ve pushed back on this in the past because “read_only” seemed inconsistent with “allow_null” from a behavioural perspective.

I’d say this, because “allow_null” is strictly something that we use to validate input.

However we’re not guarding against that case as we are for some others… https://github.com/encode/django-rest-framework/blob/master/rest_framework/fields.py#L336 …so if this is beneficial for introspection purposes, then okay. Let’s allow it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants