-
Notifications
You must be signed in to change notification settings - Fork 270
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
PrimaryKeyRelatedFields produce incorrect schema if they are read-only #274
Comments
diesieben07
added a commit
to diesieben07/drf-spectacular
that referenced
this issue
Jan 28, 2021
diesieben07
added a commit
to diesieben07/drf-spectacular
that referenced
this issue
Jan 31, 2021
diesieben07
added a commit
to diesieben07/drf-spectacular
that referenced
this issue
Jan 31, 2021
tfranzel
added a commit
that referenced
this issue
Feb 1, 2021
…ykeyrelatedfield Fix readonly related fields generating incorrect schema
tfranzel
added a commit
that referenced
this issue
Feb 25, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
PrimaryKeyRelatedField
s that are read-only are not handled correctly. When getting the model field the generator will look at the primary key of the model containing the foreign key instead of the target of the foreign key.To Reproduce
This will generate the
referenced_model
field asUUID
instead ofint
. Removingreferenced_model
fromreadonly_fields
removes this issue. This happens, because the generator will look at the PK ofReferencingModel
. The culprit is here:drf-spectacular/drf_spectacular/openapi.py
Lines 482 to 485 in f23de89
Expected behavior
A
PrimaryKeyRelatedField
should generate the correct type regardless of whether it is read-only or not.The text was updated successfully, but these errors were encountered: