Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aiohttp cors breaks with new aiohttp 3.0 release #154

Closed
idwaker opened this issue Feb 13, 2018 · 2 comments
Closed

aiohttp cors breaks with new aiohttp 3.0 release #154

idwaker opened this issue Feb 13, 2018 · 2 comments

Comments

@idwaker
Copy link

idwaker commented Feb 13, 2018

aiohttp cors setup breaks with

 File "/home/idwaker/Code/webapp/app/api/common/utils/loaders.py", line 43, in init_cors
    cors = aiohttp_cors.setup(app, defaults=CORS_DEFAULTS)
  File "/home/idwaker/.local/share/virtualenvs/webapp-69lhAx_Z/lib/python3.6/site-packages/aiohttp_cors/__init__.py", line 65, in setup
    cors = CorsConfig(app, defaults=defaults)
  File "/home/idwaker/.local/share/virtualenvs/webapp-69lhAx_Z/lib/python3.6/site-packages/aiohttp_cors/cors_config.py", line 247, in __init__
    self._resources_router_adapter)
  File "/home/idwaker/.local/share/virtualenvs/webapp-69lhAx_Z/lib/python3.6/site-packages/aiohttp_cors/cors_config.py", line 117, in __init__
    self._app.on_response_prepare.append(self._on_response_prepare)
  File "aiohttp/_frozenlist.pyx", line 97, in aiohttp._frozenlist.FrozenList.append
  File "aiohttp/_frozenlist.pyx", line 19, in aiohttp._frozenlist.FrozenList._check_frozen
RuntimeError: Cannot modify frozen list.

on latest 3.0 release of aiohttp

my init_cors is something like this

async def init_cors(app: web.Application):
    logger = get_logger(app['name'])
    cors = aiohttp_cors.setup(app, defaults=CORS_DEFAULTS)

    # add resources to cors
    for resource in list(app.router.resources()):
        if isinstance(resource, web.Resource):
            cors.add(resource)
    logger.info("Initialized CORS for {}".format(app['name']))

and i am loading init_cors on app.on_startup

The issue seems to occur when i defer cors setup to on_startup signal like

app.on_startup.append(init_cors)

But it works normally if i put the cors init code on app setup like

 # register routes here
    register_routes(app)

    cors = aiohttp_cors.setup(app, defaults=CORS_DEFAULTS)

    # add resources to cors
    for resource in list(app.router.resources()):
        if isinstance(resource, web.Resource):
            cors.add(resource)
@idwaker
Copy link
Author

idwaker commented Feb 13, 2018

I don't think the appending cors setup to startup signal was good idea anyway, so i removed that with simple function call for setup which works as desired.

@idwaker idwaker closed this as completed Feb 13, 2018
@asvetlov
Copy link
Member

@idwaker you are right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants