Commit 89a111b
fix(api): don't scope serializer querysets by AnonymousUser during schema generation
The Finding and import serializers scope their endpoint/location
PrimaryKeyRelatedField querysets to request.user. During OpenAPI schema
generation drf-spectacular instantiates serializers with an AnonymousUser
request, which is truthy, so the `if user` branch called
get_authorized_*(user=AnonymousUser); filtering a PK field by the AnonymousUser
instance raised "Field 'id' expected a number but got AnonymousUser".
drf-spectacular then ignored the affected views, producing an operationId
collision and a KeyError in the prefetch postprocessing hook.
Treat an unauthenticated user as no user so the field falls back to an empty
queryset, matching pre-existing behavior for anonymous/schema-time contexts.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 26d4032 commit 89a111b
2 files changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
518 | 518 | | |
519 | 519 | | |
520 | 520 | | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
521 | 527 | | |
522 | 528 | | |
523 | 529 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
357 | 363 | | |
358 | 364 | | |
359 | 365 | | |
| |||
0 commit comments