Answer QUERY on list views without a per-view query() handler (QueryMixin + patch()) #12
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 487 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.370
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12"
general
weight: 0.35
BenA-SA
What
This removes the per-viewset
query()boilerplate. Reviewer feedback on the blog post about the package suggested aQueryMixin, and pointed out that because the package already patches DRF,patch()could addquery()itself and make the mixin unnecessary. This PR does both, one for each of the package's two setup paths.QueryMixin(drf_query_method.mixins, also exported asdrf_query_method.QueryMixin) delegatesquery()tolist(). It's for the opt-in path, for exampleclass NoteViewSet(QueryMixin, ModelViewSet). It works with any view that haslist(), including a hand-writtenViewSet.list.patch()adds the same handler to DRF'sListModelMixin, and only to that. So every generic list view and list-capable viewset gets it, while views withoutlist(RetrieveAPIView, retrieve-only viewsets) don't. PuttingqueryonViewSetMixininstead would have made the router build a list route for viewsets that have nolist.- Routers still map
QUERYon the list route only, and detail routes return 405 withQUERYleft out ofAllow.- A
query()that a view defines itself wins through the MRO, sopatch()never overrides it.- On a viewset whose
query()is the delegating one, the routers send QUERY straight to thelistaction.self.actionis then"list", so aget_serializer_class(),get_queryset()orget_permissions()that branches on the action treats QUERY like GET and can't fall through to a detail serializer. A viewset with its ownquery()keeps thequeryaction. Seer flagged this on the PR.- An
@actionnamedquerykeeps its own route, as before.- A view can opt out by leaving
queryout ofhttp_method_names. That needs no new API.- This part also applies once DRF supports
QUERYnatively, because DRF's own support (encode/django-rest-framework#10091) only routesQUERYto views that definequery(). Otherwise upgrading DRF would silently turn these routes into 405s. The usage docs cover adding handlers before uninstalling.KeyError: 'query'on any view with aquery()handler. Oncepatch()gives every list view that handler, every drf-spectacular user's schema would break. When drf-spectacular is installed,patch()now leavesQUERYout of its schema, the same way it already does for DRF's own generator. (drf-yasg uses DRF'sget_allowed_methods, which the package already patches.) drf-spectacular is added to the test dependency group and to the CI andjust test-againstinstalls.drf_query_method.viewsetsclasses don't includeQueryMixin, so they stay explicit.Behaviour change for existing
patch()users: list endpoints that used to return 405 forQUERYnow answer it, with the same permissions and filters asGET. This is recorded under Changed in the changelog.No version bump. There's no
docs/adr/in this repo, so there's no ADR. This PR and #11 both edit the README, the usage docs andCHANGELOG/unreleased.md, so whichever merges second will need a small rebase.AI Provenance
QueryMixinsuggestion, and havepatch()add the equivalent handler where it's safe without overriding a view's ownquery().Checklist
just checkpasses (ruff format, ruff check, ty, 71 tests), andjust testallpasses on Python 3.10/Django 4.2/DRF 3.16, 3.13/5.2/3.17 and 3.14/6.1/3.18.just docs-buildis clean. Removing theListModelMixinpatch makes two tests fail, removing the drf-spectacular guard makes one fail, and removing thelistaction mapping makes three fail.