Skip to content

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
aio-libs:3.14from
HrachShah:fix/transport-sockname-attr
Open

Add _transport_sockname to BaseRequest.ATTRS to silence the spurious DeprecationWarning that aiohttp raises on its own code#13037
HrachShah wants to merge 2 commits into
aio-libs:3.14from
HrachShah:fix/transport-sockname-attr

Conversation

@HrachShah

Copy link
Copy Markdown

Fixes #13029.

BaseRequest.__init__ sets self._transport_sockname = protocol.sockname (see
aiohttp/web_request.py), but the ATTRS allowlist that Request.__setattr__
checks in DEBUG mode (-X dev or PYTHONASYNCIODEBUG=1) was missing this name.
The two peer attributes _transport_sslcontext and _transport_peername are
already in the allowlist, so the warning fires on aiohttp's own code path: any
transport that exposes a sockname (every TCP/Unix-socket server) triggers
DeprecationWarning: Setting custom BaseRequest._transport_sockname attribute is discouraged.

Fix: add _transport_sockname to BaseRequest.ATTRS so the constructor's
attribute assignment is permitted. No other changes are needed.

Test: a new test in tests/test_web_request.py constructs a
BaseRequest with a transport that returns a (host, port) tuple for
sockname, inside a warnings.catch_warnings() block with
simplefilter("error", DeprecationWarning). The test fails on the pre-fix code
with the spurious DeprecationWarning and 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.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Jul 2, 2026
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.24%. Comparing base (6ae358f) to head (09589d5).
✅ All tests successful. No failed tests found.

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     
Flag Coverage Δ
CI-GHA 98.29% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.06% <100.00%> (+<0.01%) ⬆️
OS-Windows 95.73% <100.00%> (-0.01%) ⬇️
OS-macOS 97.26% <100.00%> (+<0.01%) ⬆️
Py-3.10 97.45% <100.00%> (+<0.01%) ⬆️
Py-3.11 97.72% <100.00%> (-0.01%) ⬇️
Py-3.12 97.81% <100.00%> (+<0.01%) ⬆️
Py-3.13 97.78% <100.00%> (+<0.01%) ⬆️
Py-3.14 97.89% <100.00%> (-0.01%) ⬇️
Py-3.14t 96.89% <100.00%> (+<0.01%) ⬆️
Py-pypy-3.11 96.73% <100.00%> (-0.01%) ⬇️
VM-macos 97.26% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.06% <100.00%> (+<0.01%) ⬆️
VM-windows 95.73% <100.00%> (-0.01%) ⬇️
cython-coverage 38.46% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codspeed-hq

codspeed-hq Bot commented Jul 2, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 72 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing HrachShah:fix/transport-sockname-attr (09589d5) with 3.14 (6ae358f)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

…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.
@HrachShah HrachShah force-pushed the fix/transport-sockname-attr branch from b95b899 to e32cb06 Compare July 6, 2026 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant