-
Notifications
You must be signed in to change notification settings - Fork 260
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
Model @property and SlugRelatedField not handled properly #943
Comments
I see, will look into it. The change happened here #854. Before, we had it hard-coded as string, so there was little chance of it breaking. Now, the introspection is assuming a model field, but it looks like a model property is also viable. We have the mechanics for that, but somehow it is not triggered. I'm not exactly sure why you chose a slug here, but we should support it if it works. In the meantime, this should work too (if you add a return type forty_two = serializers.ReadOnlyField(source='property_field') |
@tfranzel For my use case, I am using
If I point the |
Yes, I get that.
Sure, because the mechanics falsely expect a model field for Anyways, this fix should do the trick. Please test it if you don't mind. P.S. Please not note that this also requires a type hint on |
closed with release |
In
v0.24.2
this works properly butv0.25.0
and onward broke how SlugRelatedField and@properties
are being handled.Describe the bug
SlugRelatedField
that reference a model@property
are not being handled.While stepping through the functions on how this field is being resolved, I tracked down how this field is being handled in
v0.25.0
.First, this logic was updated in
v0.25.0
compared tov0.24.2
.https://github.com/tfranzel/drf-spectacular/blob/master/drf_spectacular/openapi.py#L663
The SlugRelatedField will get to this function.
drf-spectacular/drf_spectacular/plumbing.py
Line 500 in 7392ba9
and will finally return this value at the end of traversal.
drf-spectacular/drf_spectacular/plumbing.py
Lines 508 to 509 in 7392ba9
Ultimately, this assertion is failing. https://github.com/tfranzel/drf-spectacular/blob/0.25.0/drf_spectacular/openapi.py#L544
Prior to this logic update,
SlugRelatedFields
used this logic to resolve. https://github.com/tfranzel/drf-spectacular/blob/0.24.2/drf_spectacular/openapi.py#L698-L699To Reproduce
API Response
Expected behavior
SlugRelatedFields that use @properties don't fail assertion and are resolved the same way they are handled in
v0.24.2
The text was updated successfully, but these errors were encountered: