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

Python 3.10: DeprecationWarnings break other packages (e.g. flask) #260

Closed
mgorny opened this issue May 20, 2021 · 5 comments
Closed

Python 3.10: DeprecationWarnings break other packages (e.g. flask) #260

mgorny opened this issue May 20, 2021 · 5 comments

Comments

@mgorny
Copy link

mgorny commented May 20, 2021

See e.g. pallets/flask#4077

It seems that asgiref is using deprecated code that is fatal to pytest in other packages, e.g. flask:

______________________________________________________________ test_async_route[/] _______________________________________________________________
tests/test_async.py:64: in test_async_route
    assert b"GET" in response.get_data()
E   assert b'GET' in b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>500 Internal Server Error</title>\n<h1>Internal Serv...nd was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n'
E    +  where b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>500 Internal Server Error</title>\n<h1>Internal Serv...nd was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>\n' = <bound method Response.get_data of <WrapperTestResponse 290 bytes [500 INTERNAL SERVER ERROR]>>()
E    +    where <bound method Response.get_data of <WrapperTestResponse 290 bytes [500 INTERNAL SERVER ERROR]>> = <WrapperTestResponse 290 bytes [500 INTERNAL SERVER ERROR]>.get_data
--------------------------------------------------------------- Captured log call ----------------------------------------------------------------
ERROR    test_async:app.py:1441 Exception on / [GET]
Traceback (most recent call last):
  File "/tmp/flask/.tox/py310/lib/python3.10/site-packages/flask/app.py", line 2052, in wsgi_app
    response = self.full_dispatch_request()
  File "/tmp/flask/.tox/py310/lib/python3.10/site-packages/flask/app.py", line 1502, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/tmp/flask/.tox/py310/lib/python3.10/site-packages/flask/app.py", line 1500, in full_dispatch_request
    rv = self.dispatch_request()
  File "/tmp/flask/.tox/py310/lib/python3.10/site-packages/flask/app.py", line 1486, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/tmp/flask/.tox/py310/lib/python3.10/site-packages/flask/app.py", line 1583, in ensure_sync
    return self.async_to_sync(func)
  File "/tmp/flask/.tox/py310/lib/python3.10/site-packages/flask/app.py", line 1615, in async_to_sync
    return asgiref_async_to_sync(func)
  File "/tmp/flask/.tox/py310/lib/python3.10/site-packages/asgiref/sync.py", line 135, in __init__
    self.main_event_loop = asyncio.get_event_loop()
DeprecationWarning: There is no current event loop

I can also reproduce the problem in asgiref if I add the following:

diff --git a/setup.cfg b/setup.cfg
index a3df063..32f7050 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -42,6 +42,8 @@ tests =
 
 [tool:pytest]
 testpaths = tests
+filterwarnings =
+    error
 
 [flake8]
 exclude = venv/*,tox/*,specs/*

Then the tests fail immediately:

$ tox -e py310-test
py310-test develop-inst-noop: /tmp/asgiref
py310-test installed: -e git+https://github.com/django/asgiref/@d6ad948055c284973789d43fce78c094abed9813#egg=asgiref,attrs==21.2.0,iniconfig==1.1.1,mypy==0.812,mypy-extensions==0.4.3,packaging==20.9,pluggy==0.13.1,py==1.10.0,pyparsing==2.4.7,pytest==6.2.4,pytest-asyncio==0.15.1,toml==0.10.2,typed-ast==1.4.3,typing-extensions==3.10.0.0
py310-test run-test-pre: PYTHONHASHSEED='488601571'
py310-test run-test: commands[0] | pytest -v
============================================================== test session starts ===============================================================
platform linux -- Python 3.10.0b1, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /tmp/asgiref/.tox/py310-test/bin/python
cachedir: .tox/py310-test/.pytest_cache
rootdir: /tmp/asgiref, configfile: setup.cfg, testpaths: tests
plugins: asyncio-0.15.1
collected 27 items / 1 error / 26 selected                                                                                                       

===================================================================== ERRORS =====================================================================
______________________________________________________ ERROR collecting tests/test_sync.py _______________________________________________________
tests/test_sync.py:577: in <module>
    class ASGITest(TestCase):
tests/test_sync.py:583: in ASGITest
    async def test_wrapped_case_is_collected(self):
asgiref/sync.py:135: in __init__
    self.main_event_loop = asyncio.get_event_loop()
E   DeprecationWarning: There is no current event loop
============================================================ short test summary info =============================================================
ERROR tests/test_sync.py - DeprecationWarning: There is no current event loop
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================ 1 error in 0.13s ================================================================
ERROR: InvocationError for command /tmp/asgiref/.tox/py310-test/bin/pytest -v (exited with code 2)
____________________________________________________________________ summary _____________________________________________________________________
ERROR:   py310-test: commands failed
@carltongibson
Copy link
Member

get_running_loop is available from Python 3.7. It may be time to consider dropping Python 3.6, as there are just too many Python versions to support at once. (Just a suggestion.)

@mgorny
Copy link
Author

mgorny commented May 20, 2021

That would work for me. Gentoo has dropped support for Python 3.6 in January, as maintaining it was PITA after IPython & co. dropped support.

@andrewgodwin
Copy link
Member

I'm in support of dropping 3.6, but Django 3.2 still supports it, so we'd have to do a major version bump in order to pull this off.

@andrewgodwin
Copy link
Member

Ah, and Flask 2 still supports 3.6, and they have a version pin on asgiref with an unlimited upper boundary (so even bumping to v4 would not help). I've filed a ticket to try and get that resolved, but what it means is that we have to support 3.6 for at least this year.

@andrewgodwin
Copy link
Member

Fixed by #262

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

3 participants