[PR #13301/58bae08b backport][3.15] Add METH_QUERY and treat QUERY as an idempotent method - #13318
Open
rodrigobnogueira wants to merge 1 commit into
Conversation
(cherry picked from commit 58bae08)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.15 #13318 +/- ##
=======================================
Coverage 98.27% 98.27%
=======================================
Files 136 136
Lines 49417 49432 +15
Branches 2666 2667 +1
=======================================
+ Hits 48563 48579 +16
Misses 674 674
+ Partials 180 179 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
rodrigobnogueira
marked this pull request as ready for review
August 4, 2026 03:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a backport of PR #13301 as merged into master (58bae08).
What do these changes do?
Follow-up to #13160, as requested in #13160 (comment).
#13174 fixed the parser half of that issue, so
QUERYnow arrives intact instead of<unknown>. The two remaining pieces (originally part of the closed #13167) never landed:aiohttp/hdrs.pygainsMETH_QUERY, alongside the otherMETH_*constants.aiohttp/client.pyadds"QUERY"toIDEMPOTENT_METHODS, so aQUERYrequest is replayed when the server closes a keep-alive connection underneath it, the same asGETorPUT. RFC 10008 defines the method as both safe and idempotent (https://www.rfc-editor.org/info/rfc10008/#section-1-12), which is exactly the property that set encodes.METH_QUERYis deliberately not added toMETH_ALL.RouteDef.register()dispatches everyMETH_ALLmember throughgetattr(router, "add_" + method.lower()), andUrlDispatcherhas noadd_query(), so adding it there would turnweb.route("QUERY", ...)passed toadd_routes()into anAttributeError. (METH_CONNECTandMETH_TRACEare already inMETH_ALLwithout matchingadd_*methods, so that path is broken for them today — out of scope here.)Are there changes in behavior for the user?
Yes, one: a
QUERYrequest that hits a keep-alive connection the server has just closed is now retried once instead of raisingServerDisconnectedError. That is the documented behavior for safe, idempotent methods, andQUERYqualifies. Everything else is additive — a new public constant.Is it a substantial burden for the maintainers to support this?
No. It is one constant and one set member, with no new code paths; the retry logic itself is untouched.
Related issue number
Follows up #13160 (fixed for the parser by #13174). Reuses the
hdrs.py/client.pyhunks from the closed #13167, with the RFC URL amended to the form suggested in review there.Checklist
hdrsconstants are not individually documented and the retry behavior is described genericallyCONTRIBUTORS.txt— N/A, already listedCHANGES/folderTest evidence
New test
test_retry_persistent_connection_query_methodsits alongside the existingtest_retry_persistent_connection_lowercase_method, and follows the same shape: the handler force-closes the connection on the first request, and the test asserts the request is retried.Passes with both parsers:
Confirmed the test fails without the production change (reverting
IDEMPOTENT_METHODSto its previous value makes it error with the connection dropped, no retry), so it is not vacuous.Wider run, no regressions:
black,isortandmypyare clean on the touched files.