-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
In web_protocol.py, log_access checks for the following:
if self.access_logger is not None and self.access_logger.enabled
which guards against this code
self._loop.time() - time.
It is possible to get here in unit tests with time == None, causing a TypeError
self.access_logger.enabled is a property that can change if the logging level changes, but time is set based on
start = loop.time() if self._logging_enabled else None
And self._logging_enabled is set on init only
Usually this is fine since log levels will be set way before the RequestHandler init, but in unit tests the log level can instead be set with a call to self.assertLogs(), which could be called far after the RequestHandler init
To Reproduce
- Create a generic server with a single endpoint
- Separately, create a test against that server using AioHTTPTestCase, but do not set up any logging. Call the endpoint in that case within a with self.assertLogs() block
- See this line assert on time being None
self.access_logger.log(request, response, self._loop.time() - time)
Expected behavior
RequestHandler correctly handles log levels changing post-init
Logs/tracebacks
.Python Version
$ python --version
Python 3.11.3aiohttp Version
$ python -m pip show aiohttp
3.13.2multidict Version
$ python -m pip show multidict
6.7.0propcache Version
$ python -m pip show propcache
0.4.1yarl Version
$ python -m pip show yarl
1.22.0OS
Ubuntu 20.04
Related component
Server
Additional context
No response
Code of Conduct
- I agree to follow the aio-libs Code of Conduct