-
-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
Describe the bug
Using Background logger
with exc_info
causes a TypeError
.
To Reproduce
from sanic import Sanic, text
from sanic.log import logger
app = Sanic("logging")
app.config.LOGGING = True
@app.get("/")
async def error(request):
try:
1 / 0
except Exception as e:
logger.error("Error occurred", exc_info=e)
return text("OK")
if __name__ == "__main__":
app.run(debug=True)
Expected behavior
Expect logs to be recorded normally.
Environment (please complete the following information):
- OS: macOS-15.3.2-x86_64-i386-64bit
- Browser: Chrome
- Version: python 3.12.9, Sanic v25.3.0, sanic-routing==23.12.0, sanic-ext==24.12.0
Additional context
Error while handling error: 'NoneType' object has no attribute '__name__'
Stack: Traceback (most recent call last):
File "/Users/xylitol/Downloads/test/test.py", line 10, in error
1 / 0
~~^~~
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/xylitol/Downloads/test/test/lib/python3.12/site-packages/sanic/app.py", line 1381, in handle_request
response = await response
^^^^^^^^^^^^^^
File "/Users/xylitol/Downloads/test/test.py", line 12, in error
logger.error("Error occurred", exc_info=e)
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1568, in error
self._log(ERROR, msg, args, **kwargs)
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1684, in _log
self.handle(record)
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1700, in handle
self.callHandlers(record)
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
hdlr.handle(record)
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1028, in handle
self.emit(record)
File "/Users/xylitol/Downloads/test/test/lib/python3.12/site-packages/sanic_ext/extensions/logging/logger.py", line 42, in emit
return super().enqueue(record)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/handlers.py", line 1454, in enqueue
self.queue.put_nowait(record)
File "<string>", line 2, in put_nowait
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/multiprocessing/managers.py", line 827, in _callmethod
conn.send((self._id, methodname, args, kwds))
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/multiprocessing/connection.py", line 206, in send
self._send_bytes(_ForkingPickler.dumps(obj))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/multiprocessing/reduction.py", line 51, in dumps
cls(buf, protocol).dump(obj)
TypeError: cannot pickle 'traceback' object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/xylitol/Downloads/test/test/lib/python3.12/site-packages/sanic/handlers/error.py", line 132, in response
response = self.default(request, exception)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xylitol/Downloads/test/test/lib/python3.12/site-packages/sanic/handlers/error.py", line 174, in default
self.log(request, exception)
File "/Users/xylitol/Downloads/test/test/lib/python3.12/site-packages/sanic/handlers/error.py", line 203, in log
error_logger.exception(
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1574, in exception
self.error(msg, *args, exc_info=exc_info, **kwargs)
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1568, in error
self._log(ERROR, msg, args, **kwargs)
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1684, in _log
self.handle(record)
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1700, in handle
self.callHandlers(record)
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
hdlr.handle(record)
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/__init__.py", line 1028, in handle
self.emit(record)
File "/Users/xylitol/Downloads/test/test/lib/python3.12/site-packages/sanic_ext/extensions/logging/logger.py", line 42, in emit
return super().enqueue(record)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/logging/handlers.py", line 1454, in enqueue
self.queue.put_nowait(record)
File "<string>", line 2, in put_nowait
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/multiprocessing/managers.py", line 827, in _callmethod
conn.send((self._id, methodname, args, kwds))
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/multiprocessing/connection.py", line 206, in send
self._send_bytes(_ForkingPickler.dumps(obj))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xylitol/.pyenv/versions/3.12.9/lib/python3.12/multiprocessing/reduction.py", line 51, in dumps
cls(buf, protocol).dump(obj)
TypeError: cannot pickle 'traceback' object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/xylitol/Downloads/test/test/lib/python3.12/site-packages/sanic/app.py", line 1222, in handle_exception
response = self.error_handler.response(request, exception)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/xylitol/Downloads/test/test/lib/python3.12/site-packages/sanic/handlers/error.py", line 141, in response
error_logger.exception(response_message, handler.__name__, url)
^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__name__'. Did you mean: '__ne__'?
Metadata
Metadata
Assignees
Labels
No labels