-
Notifications
You must be signed in to change notification settings - Fork 258
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
Detect path parameter type for nested routes from rest_framework_nested #453
Comments
Solution I use: Adding Hope this helps someone facing similar issue |
this might be related to #251. are you using the most recent version of spectacular? i was under the impression that we fixed the pk/id issue. at least that is what that PR was about. |
@tfranzel tried with I still see warnings similar to this if I remove Warning #0: XXXViewSet: could not derive type of path parameter "client_pk" because model "<class 'accounts.models.client.XXX'>" did contain no such field. Consider annotating parameter with @extend_schema. Defaulting to "string". |
The following also does not work as it results in a parameter of class ObjectViewSet(ModelViewSet):
lookup_field = "custom_field"
class SubObjectViewSet(ModelViewSet):
pass I'm not sure if there are any other implications, but I removed the type warning via - @extend_schema(parameters=[OpenApiParameter("object_custom_field", str, OpenApiParameter.PATH)])
class SubObjectViewSet(ModelViewSet):
pass |
Thanks for the update @tfranzel! Unfortunately I see the same behaviour as in this comment: #453 (comment) >> import drf_spectacular
>> drf_spectacular.__version__
'0.18.2'
>> import rest_framework_nested
>> rest_framework_nested.__version__
'0.93.3'
>> import django
>> django.__version__
'3.2.7'
>> import rest_framework
>> rest_framework.__version__
'3.12.4' [16/Sep/2021 06:41:07] "GET /api-docs/swagger-ui/ HTTP/1.1" 200 1213
Warning #0: Child1ViewSet: could not derive type of path parameter "domain_pk" because model "<class 'app.models.Child1Model'>" did contain no such field. Consider annotating parameter with @extend_schema. Defaulting to "string".
Warning #1: Child2ViewSet: could not derive type of path parameter "domain_pk" because model "<class 'app.models.Child2Model'>" did contain no such field. Consider annotating parameter with @extend_schema. Defaulting to "string". |
@tiholic this has not been released yet. have you installed the current master branch of drf-spectacular? the warning changed since since 0.18.2 release. if |
this has been severely improved in ba2f799 (and prior commits). path variable detection should now work as expected without using related but independent from that, a new setting |
Looks like the fix was released in 0.19.0. Working just fine! 🎉 |
I hope it's fine to comment on this issue. But for me I'm getting params parsed but as an int. /v1/level-one/{custom_id}/level-two:
get:
operationId: levelone_leveltwo_list
parameters:
- in: path
name: custom_id
schema:
type: integer
required: true I though this is a issue for drf-nested-routers but digging inside a bit I find out that it's the same regex generated for the non-nested routes, which is giving the correct type string. The lookup regex is the following: |
but what is it then? are there warning emitted to the console? spectacular should default to
that is the default regex for all of DRF's path parameters. if spectacular sees that, it tries to be smarter and find a field type for that name for further discussion please open a new issue. |
I'm using drf-spectacular==0.21.2 and rest_framework_nested==0.93.4 but I'm getting
if I use I tried also to use |
Hi @lucadelu, this is fully tested here:
The error says it was unable to get the model/querset, and i think it is unrelated to
You can explicitly exclude detected parameters with
for further discussion please open a new issue. |
I provided queryset and it works, thanks
ok thanks a lot |
To create nested Viewsets, I'm using https://github.com/alanjds/drf-nested-routers
Route registration happens like this:
and methods in viewset are expected an additional keyword argument with
<lookup>_pk
:This will log a warning:
The text was updated successfully, but these errors were encountered: