Add _transport_sockname to BaseRequest.ATTRS to silence the spurious DeprecationWarning that aiohttp raises on its own code#13037
Open
HrachShah wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.14 #13037 +/- ##
=======================================
Coverage 98.24% 98.24%
=======================================
Files 135 135
Lines 48774 48782 +8
Branches 2613 2613
=======================================
+ Hits 47916 47925 +9
Misses 678 678
+ 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
|
…DeprecationWarning that aiohttp raises on its own code.
BaseRequest.__init__ sets self._transport_sockname = protocol.sockname, but the
allowlist of attributes that Request.__setattr__ permits in DEBUG mode (ATTRS) was
missing this name. Any code path that constructs a BaseRequest under -X dev or
PYTHONASYNCIODEBUG=1 (including the project's own benchmarks) trips the
DeprecationWarning "Setting custom BaseRequest._transport_sockname attribute is
discouraged".
The peers _transport_sslcontext and _transport_peername are already in ATTRS, so
adding _transport_sockname alongside them is the obvious fix.
Test asserts that constructing a request with a transport that exposes a sockname
does not raise a DeprecationWarning under a simplefilter("error", DeprecationWarning).
Closes aio-libs#13029.
b95b899 to
e32cb06
Compare
for more information, see https://pre-commit.ci
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.
Fixes #13029.
BaseRequest.__init__setsself._transport_sockname = protocol.sockname(seeaiohttp/web_request.py), but theATTRSallowlist thatRequest.__setattr__checks in DEBUG mode (
-X devorPYTHONASYNCIODEBUG=1) was missing this name.The two peer attributes
_transport_sslcontextand_transport_peernamearealready in the allowlist, so the warning fires on aiohttp's own code path: any
transport that exposes a
sockname(every TCP/Unix-socket server) triggersDeprecationWarning: Setting custom BaseRequest._transport_sockname attribute is discouraged.Fix: add
_transport_socknametoBaseRequest.ATTRSso the constructor'sattribute assignment is permitted. No other changes are needed.
Test: a new test in
tests/test_web_request.pyconstructs aBaseRequestwith a transport that returns a(host, port)tuple forsockname, inside awarnings.catch_warnings()block withsimplefilter("error", DeprecationWarning). The test fails on the pre-fix codewith the spurious
DeprecationWarningand passes with the fix applied.Verified with
python3 -X dev -m pytest tests/test_web_request.py→ 132 passed(131 pre-existing + 1 new). Also ran
python3 -X dev -m pytest tests/test_web_request.py tests/test_web_response.py tests/test_run_app.py→ 0 failures.CHANGES fragment at
CHANGES/13029.bugfix.rst.