You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm running Sanic as part of a larger async codebase. I'm using the run_async.py example as a blueprint. If you run this code, and visit the website, everything works as normal. However, on every page-load, this traceback is printed:
[2024-04-29 13:41:43 +0200] [34199] [ERROR] Exception occurred in one of response middleware handlers
Traceback (most recent call last):
File "<..>/venv-311/lib/python3.11/site-packages/sanic/request/types.py", line 402, in respond
response = await self.app._run_response_middleware(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "_run_response_middleware", line 17, in _run_response_middleware
from asyncio.futures import Future
^^^^^^^^^^^
File "<..>/venv-311/lib/python3.11/site-packages/sanic_ext/extensions/http/cors.py", line 54, in _add_cors_headers
_add_origin_header(request, response)
File "<..>/venv-311/lib/python3.11/site-packages/sanic_ext/extensions/http/cors.py", line 160, in _add_origin_header
allow_origins = _get_from_cors_ctx(
^^^^^^^^^^^^^^^^^^^
File "<..>/venv-311/lib/python3.11/site-packages/sanic_ext/extensions/http/cors.py", line 151, in _get_from_cors_ctx
value = getattr(request.route.ctx._cors, key, default)
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'types.SimpleNamespace' object has no attribute '_cors'
Code snippet
No response
Expected Behavior
No response
How do you run Sanic?
As a module
Operating System
Linux
Sanic Version
23.12.0
Additional context
No response
The text was updated successfully, but these errors were encountered:
This is indeed very annoying, and it probably means that CORS will not work correctly at all.
This probably happens because the internal _cors attribute is created via a before_server_start hook, and that hook does not get called when not using the normal app.run.
This seems like a design oversight, and it should really be addressed.
If you don't need/want CORS, then you can get rid of the error by setting app.config.CORS = False to disable CORS completely,
But if you do want CORS, then this is a blocker. And it is pretty difficult to create a workaround, since _assign_cors_settings is defined as an inner function, which prevents it from being imported and called like a normal function.
Is there an existing issue for this?
Describe the bug
I'm running Sanic as part of a larger async codebase. I'm using the run_async.py example as a blueprint. If you run this code, and visit the website, everything works as normal. However, on every page-load, this traceback is printed:
Code snippet
No response
Expected Behavior
No response
How do you run Sanic?
As a module
Operating System
Linux
Sanic Version
23.12.0
Additional context
No response
The text was updated successfully, but these errors were encountered: