sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cors related traceback on `run_async.py`

LasseBlaauwbroek opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

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:

[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