← Back to Pull requests

Add support for the HTTP QUERY method (RFC 10008) #10091

Open
unknown opened this pull request with 609 lines diff across 7 files
View on GitHub
unknown unknown commented on Oct 30, 2026 19:03 UTC
Author

Refs discussion #10024.

Django 6.2 adds the QUERY method from RFC 10008 (django/django#21855): safe and idempotent like GET, but with a request body. It adds "query" to View.http_method_names, treats QUERY as CSRF-safe, and adds RequestFactory.query().

That already breaks DRF against Django main: two tests in tests/test_decorators.py map every name in http_method_names onto http.HTTPMethod, which has no QUERY member. This PR fixes those and adds support for QUERY on every supported Django version. On Django 6.1 and earlier it adds QUERY the same way compat.py already adds PATCH, and matches Django 6.2's CSRF handling, so QUERY behaves 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

  • Permissions: QUERY is added to SAFE_METHODS, matching the RFC and Django's CSRF handling. It is also added with no required permissions ('QUERY': []) to the perms_map of both DjangoModelPermissions and DjangoObjectPermissions. If a project overrides perms_map and doesn't list QUERY, those classes refuse it with 405.

  • Routers and viewsets: SimpleRouter maps QUERY to a viewset's query() on the list route only. Viewsets that don't define query() are unaffected. A viewset only answers QUERY on routes that map it, so detail routes return 405 and leave it out of Allow. An existing @action named query keeps its own route and isn't bound to the QUERY method.

  • Request.filter_params: for a QUERY request, 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 simply query_params. SearchFilter and OrderingFilter read from it, so a QUERY list 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.

  • Django before 6.2: compat.py adds query to View.http_method_names, as it already does for patch. Without it, viewset and router query() 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.

  • CSRF: SessionAuthentication doesn't require a CSRF token for QUERY. Django 6.2 exempts it itself; on earlier versions session-authenticated QUERY requests without a token were rejected with 403.

  • Test client: APIRequestFactory.query() and APIClient.query() accept format and content_type, like post(). MethodMapper gains .query().

  • Schemas: the deprecated OpenAPI generator skips QUERY, because OpenAPI 3.0 has no query operation.

  • Docs: views, viewsets, requests, filtering, permissions, routers, testing, schemas and the CSRF topic.
  • Things worth reviewing

  • SAFE_METHODS. This is the line with the most security impact. IsAuthenticatedOrReadOnly and DjangoModelPermissionsOrAnonReadOnly will now let anonymous users send QUERY to views that handle it. A QUERY handler must therefore never write, which is what the RFC requires. Django makes the same call for CSRF.

  • filter_params is the only new public API. Without it, the built-in filters ignore the body of a QUERY request. It also gives third-party filter backends one place to read QUERY parameters 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.

  • A viewset attribute named query. If a viewset has a non-handler attribute or helper method called query, Django 6.2 already treats it as a QUERY handler. With AllowAny that crashes upstream on every route. With this PR it is limited to the list route, but combined with DjangoModelPermissions that route now returns 500 rather than 405. Because compat.py now adds QUERY on earlier Django versions too, this applies there as well, including to plain Django views with a query attribute, as it will on 6.2.
  • Not included

  • Adding Django 6.2 to tox and the classifiers. I've left this for the usual PR at the RC stage, since there is no 6.2 pre-release on PyPI yet.

  • drf-spectacular support. It crashes on views that define 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 QUERY tests run on every Django version.

  • Django 6.1: 1682 passed

  • Django main (6.2.dev): 1682 passed

  • pre-commit: clean
  • Diff: 609 lines (+456 / -153) across 7 files Reviewer: BenA-SA Review duration: 45971m
    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
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57.2% (MEDIUM) · Higher = larger blast radius
    57.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.6% · Safe to merge
    31.6%