Add support for the HTTP QUERY method (RFC 10008) #10091
All Vouch review confidence checks passed
Residual risk 0.32 = Change Risk (0.57) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 609 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.384
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #10091"
general
weight: 0.35
BenA-SA
Refs discussion #10024.
Django 6.2 adds the
QUERYmethod from RFC 10008 (django/django#21855): safe and idempotent likeGET, but with a request body. It adds"query"toView.http_method_names, treatsQUERYas CSRF-safe, and addsRequestFactory.query().That already breaks DRF against Django main: two tests in
tests/test_decorators.pymap every name inhttp_method_namesontohttp.HTTPMethod, which has noQUERYmember. This PR fixes those and adds support forQUERYon every supported Django version. On Django 6.1 and earlier it addsQUERYthe same waycompat.pyalready addsPATCH, and matches Django 6.2's CSRF handling, soQUERYbehaves the same on all of them.Size
| | Added | Removed |
|---|---|---|
| Library code (
rest_framework/) | 85 | 9 || Tests (
tests/) | 402 | 4 || Docs (
docs/) | 82 | 8 |The change to how DRF behaves is 85 lines. 32 of those add
Request.filter_params. Most of the diff is tests.Changes
QUERYis added toSAFE_METHODS, matching the RFC and Django's CSRF handling. It is also added with no required permissions ('QUERY': []) to theperms_mapof bothDjangoModelPermissionsandDjangoObjectPermissions. If a project overridesperms_mapand doesn't listQUERY, those classes refuse it with 405.SimpleRoutermapsQUERYto a viewset'squery()on the list route only. Viewsets that don't definequery()are unaffected. A viewset only answersQUERYon routes that map it, so detail routes return 405 and leave it out ofAllow. An existing@actionnamedquerykeeps its own route and isn't bound to theQUERYmethod.Request.filter_params: for aQUERYrequest, this merges the parsed body over the URL query parameters, with the body winning when a key appears in both. For every other method it is simplyquery_params.SearchFilterandOrderingFilterread from it, so aQUERYlist view can carry its filters in the body. Pagination parameters still come from the URL. If the body isn't a JSON object or form, filtering returns 400.compat.pyaddsquerytoView.http_method_names, as it already does forpatch. Without it, viewset and routerquery()handlers returned 405 while@api_view(["QUERY"])worked. Thanks to @ege-arhan, who spotted this and suggested the fix; they're credited as co-author on that commit.SessionAuthenticationdoesn't require a CSRF token forQUERY. Django 6.2 exempts it itself; on earlier versions session-authenticatedQUERYrequests without a token were rejected with 403.APIRequestFactory.query()andAPIClient.query()acceptformatandcontent_type, likepost().MethodMappergains.query().QUERY, because OpenAPI 3.0 has no query operation.Things worth reviewing
SAFE_METHODS. This is the line with the most security impact.IsAuthenticatedOrReadOnlyandDjangoModelPermissionsOrAnonReadOnlywill now let anonymous users sendQUERYto views that handle it. AQUERYhandler must therefore never write, which is what the RFC requires. Django makes the same call for CSRF.filter_paramsis the only new public API. Without it, the built-in filters ignore the body of aQUERYrequest. It also gives third-party filter backends one place to readQUERYparameters from, and I plan to propose using it in django-filter and django-rest-framework-datatables, so I'd prefer to keep it in this PR.query. If a viewset has a non-handler attribute or helper method calledquery, Django 6.2 already treats it as aQUERYhandler. WithAllowAnythat crashes upstream on every route. With this PR it is limited to the list route, but combined withDjangoModelPermissionsthat route now returns 500 rather than 405. Becausecompat.pynow addsQUERYon earlier Django versions too, this applies there as well, including to plain Django views with aqueryattribute, as it will on 6.2.Not included
query(), so I'll raise that with drf-spectacular separately.Testing
Each new test was checked by reverting the line of code it covers and confirming that it fails. The
QUERYtests run on every Django version.