aio-libs / aiohttp

Asynchronous HTTP client/server framework for asyncio and Python
https://docs.aiohttp.org
Other
15.14k stars 2.02k forks source link

aiohttp webserver with python 3.7 broken #1839

Closed wumpus closed 7 years ago

wumpus commented 7 years ago

I have python3.7-dev and python-nightly in my CI script. Recently they started failing when I call app.router.add_get()

This is a minimal reproducer, works on 3.6 and fails on 3.7-dev

import re

r = re.compile(re.escape('/foo'))
print(r)
print(r.pattern)
assert r.pattern.startswith('\\/')

Python 3.7-dev output:

re.compile('/foo')
/foo
Traceback (most recent call last):
 File "aiohttp-issue.py", line 6, in <module>
   assert r.pattern.startswith('\\/')
AssertionError

python 3.6.0 output (success):

re.compile('\\/foo')
\/foo

This is the actual traceback my full app gets in 3.7-dev and aiohttp-2.0.7:

Traceback (most recent call last):
  File "../scripts/crawl.py", line 89, in <module>
    main()
  File "../scripts/crawl.py", line 67, in main
    app = webserver.make_app(loop, config)
  File "/home/travis/build/cocrawler/cocrawler/cocrawler/webserver.py", line 16, in make_app
    app.router.add_get('/api/{name}', api)
  File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/aiohttp/web_urldispatcher.py", line 865, in add_get
    self.add_route(hdrs.METH_HEAD, *args, name=head_name, **kwargs)
  File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/aiohttp/web_urldispatcher.py", line 823, in add_rout
    resource = self.add_resource(path, name=name)
  File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/aiohttp/web_urldispatcher.py", line 817, in add_resource
    resource = DynamicResource(compiled, formatter, name=name)
  File "/home/travis/virtualenv/python3.7-dev/lib/python3.7/site-packages/aiohttp/web_urldispatcher.py", line 332, in __init__
    assert pattern.pattern.startswith('\\/')
AssertionError

Your environment

The above 3.6 and 3.7 output was run on CentOS 7 with python installed by pyenv.

fafhrd91 commented 7 years ago

That's seems like regression in cpython.

wumpus commented 7 years ago

Oh, right, I didn't check the documentation for "re" -- after looking at compiled.pattern I think you're correct.

wumpus commented 7 years ago

http://bugs.python.org/issue30147

wumpus commented 7 years ago

The python folks say that re.escape() was escaping too much in the past, and has been fixed. Their response to my bug report was to add more documentation to "porting to 3.7".

http://bugs.python.org/issue29995 -- bug for re.escape over-escaping

http://bugs.python.org/issue30147 -- my bug report

So, basically, they say your test is now wrong.

fafhrd91 commented 7 years ago

does it work with "python -OO "?

wumpus commented 7 years ago

Yes, python 3.7-dev passes with "python -OO". Which is pretty weird.

$ pyenv local 3.7-dev
$ python bug.py
re.compile('/foo')
/foo
Traceback (most recent call last):
  File "bug.py", line 6, in <module>
    assert r.pattern.startswith('\\/')
AssertionError
$ python -OO bug.py
re.compile('/foo')
/foo
fafhrd91 commented 7 years ago

but does web server work?

fafhrd91 commented 7 years ago

@asvetlov could you look into this problem too?

asvetlov commented 7 years ago

@wumpus thanks for raising the issue

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

If you feel like there's important points made in this discussion, please include those exceprts into that new issue.