Open
Description
I'm trying to use aiohttp-cors with aiohttp-graphl, which registers a route with the '*' method. I get
ValueError: <PlainResource 'graphql' /graphql> already has a '*' handler for all methods
Here is a small reproducer showing that '*' is different:
import asyncio
import aiohttp
import aiohttp_cors
from aiohttp.web_runner import GracefulExit
async def handler(request):
return aiohttp.web.Response(text="Hello!")
app = aiohttp.web.Application()
cors = aiohttp_cors.setup(app)
routes = [{
'method': 'GET',
'path': '/test',
'handler': handler,
'name': 'test-good'
}, {
'method': '*', # ValueError: <PlainResource 'another-route' /another-route> already has a '*' handler for all methods
'path': '/another-route',
'handler': handler,
'name': 'another-route'
}, ]
for route in routes:
print('creating a route for method', route['method'])
cors.add(
app.router.add_route(
method=route['method'],
path=route['path'],
handler=route['handler'],
name=route['name']
)
)
web.run_app(app, host='localhost', port=8081)
which prints
creating a route for method GET
creating a route for method *
Traceback (most recent call last):
...
ValueError: <PlainResource 'another-route' /another-route> already has a '*' handler for all methods
Reading the aiohttp-cors code I can see that _is_web_view() is False and then causes this confusing message? But only for method '*' and not GET.
I hacked the aiohttp-cors code to create separate routes for all the methods other than OPTIONS, and my program now runs successfully. But obviously that's not a fix.
Metadata
Metadata
Assignees
Labels
No labels