From 9d879af25ff371bef478eba3231c747412163dda Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 13:57:05 +0100 Subject: [PATCH 01/14] fix(ci): Unpin pytest, stop testing eventlet * eventlet is broken all the time in newer Python versions * Channels 3.0 needs some adjustments. * unpin pytest to satisfy conflicts between Python 3.9 and Python 2.7 environments --- test-requirements.txt | 3 +-- tests/conftest.py | 16 ++++++++++++++-- tests/integrations/django/myapp/routing.py | 2 +- tox.ini | 22 ++++------------------ 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index 3ba7e1a44c..9ac53b90a3 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,4 @@ -pytest==3.7.3 +pytest pytest-forked==1.1.3 tox==3.7.0 Werkzeug==0.15.5 @@ -9,7 +9,6 @@ pyrsistent==0.16.0 # TODO(py3): 0.17.0 requires python3, see https://github.com/ mock # for testing under python < 3.3 gevent -eventlet newrelic executing diff --git a/tests/conftest.py b/tests/conftest.py index 35631bcd70..6bef63e5ab 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,8 +4,15 @@ import pytest import jsonschema -import gevent -import eventlet +try: + import gevent +except ImportError: + gevent = None + +try: + import eventlet +except ImportError: + eventlet = None import sentry_sdk from sentry_sdk._compat import reraise, string_types, iteritems @@ -284,6 +291,9 @@ def read_flush(self): ) def maybe_monkeypatched_threading(request): if request.param == "eventlet": + if eventlet is None: + pytest.skip("no eventlet installed") + try: eventlet.monkey_patch() except AttributeError as e: @@ -293,6 +303,8 @@ def maybe_monkeypatched_threading(request): else: raise elif request.param == "gevent": + if gevent is None: + pytest.skip("no gevent installed") try: gevent.monkey.patch_all() except Exception as e: diff --git a/tests/integrations/django/myapp/routing.py b/tests/integrations/django/myapp/routing.py index 796d3d7d56..ea224c2221 100644 --- a/tests/integrations/django/myapp/routing.py +++ b/tests/integrations/django/myapp/routing.py @@ -1,4 +1,4 @@ from channels.http import AsgiHandler from channels.routing import ProtocolTypeRouter -application = ProtocolTypeRouter({"http": AsgiHandler}) +application = ProtocolTypeRouter({"http": AsgiHandler()}) diff --git a/tox.ini b/tox.ini index cedf7f5bf0..ecb35de6c1 100644 --- a/tox.ini +++ b/tox.ini @@ -94,25 +94,12 @@ deps = django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: djangorestframework>=3.0.0,<4.0.0 - ; TODO: right now channels 3 is crashing tests/integrations/django/asgi/test_asgi.py - ; see https://github.com/django/channels/issues/1549 - {py3.7,py3.8,py3.9}-django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: channels>2,<3 - {py3.7,py3.8,py3.9}-django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: pytest-asyncio==0.10.0 + {py3.7,py3.8,py3.9}-django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: channels>2 + {py3.7,py3.8,py3.9}-django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: pytest-asyncio {py2.7,py3.7,py3.8,py3.9}-django-{1.11,2.2,3.0,3.1,dev}: psycopg2-binary - django-{1.6,1.7,1.8}: pytest-django<3.0 - - ; TODO: once we upgrade pytest to at least 5.4, we can split it like this: - ; django-{1.9,1.10,1.11,2.0,2.1}: pytest-django<4.0 - ; django-{2.2,3.0,3.1}: pytest-django>=4.0 - - ; (note that py3.9, on which we recently began testing, only got official - ; support in pytest-django >=4.0, so we probablly want to upgrade the whole - ; kit and kaboodle at some point soon) - - ; see https://pytest-django.readthedocs.io/en/latest/changelog.html#v4-0-0-2020-10-16 - django-{1.9,1.10,1.11,2.0,2.1,2.2,3.0,3.1}: pytest-django<4.0 - + django-{1.9,1.10,1.11,2.0,2.1}: pytest-django<4.0 + django-{2.2,3.0,3.1}: pytest-django>=4.0 django-dev: git+https://github.com/pytest-dev/pytest-django#egg=pytest-django django-1.6: Django>=1.6,<1.7 @@ -332,7 +319,6 @@ deps = mock # for testing under python < 3.3 gevent - eventlet newrelic executing From 8096a1677acf5ff94e416f11a0d89fd393ab7e9b Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 14:04:17 +0100 Subject: [PATCH 02/14] install pytest-django for old django too --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index ecb35de6c1..c3bbcbb804 100644 --- a/tox.ini +++ b/tox.ini @@ -98,6 +98,7 @@ deps = {py3.7,py3.8,py3.9}-django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: pytest-asyncio {py2.7,py3.7,py3.8,py3.9}-django-{1.11,2.2,3.0,3.1,dev}: psycopg2-binary + django-{1.6,1.7,1.8}: pytest-django<3.0 django-{1.9,1.10,1.11,2.0,2.1}: pytest-django<4.0 django-{2.2,3.0,3.1}: pytest-django>=4.0 django-dev: git+https://github.com/pytest-dev/pytest-django#egg=pytest-django From 578356fca71ec7305c27abc6dbe8a776fc5c9a89 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 14:15:58 +0100 Subject: [PATCH 03/14] downgrade pytest for old flask --- tox.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tox.ini b/tox.ini index c3bbcbb804..0cca7925d2 100644 --- a/tox.ini +++ b/tox.ini @@ -127,6 +127,9 @@ deps = ; flask-dev: git+https://github.com/pallets/flask.git#egg=flask ; flask-dev: git+https://github.com/pallets/werkzeug.git#egg=werkzeug + # https://github.com/pytest-dev/pytest/issues/5532 + flask-{0.10,0.11,0.12}: pytest<5 + bottle-0.12: bottle>=0.12,<0.13 bottle-dev: git+https://github.com/bottlepy/bottle#egg=bottle From cf1c45c074065d4e554a761713ff22a958cae900 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 15:17:02 +0100 Subject: [PATCH 04/14] fix flask 1.11 error --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 0cca7925d2..e911301594 100644 --- a/tox.ini +++ b/tox.ini @@ -128,7 +128,7 @@ deps = ; flask-dev: git+https://github.com/pallets/werkzeug.git#egg=werkzeug # https://github.com/pytest-dev/pytest/issues/5532 - flask-{0.10,0.11,0.12}: pytest<5 + {py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12}: pytest<5 bottle-0.12: bottle>=0.12,<0.13 bottle-dev: git+https://github.com/bottlepy/bottle#egg=bottle From 7084b1145d1c9bc421fb6a8157f2c01dc2ef1dd2 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 15:46:21 +0100 Subject: [PATCH 05/14] revert flask-dev hack, new pip resolver has landed --- test-requirements.txt | 2 +- tox.ini | 41 +++-------------------------------------- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index 9ac53b90a3..1289b7a38d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,7 +1,7 @@ pytest pytest-forked==1.1.3 tox==3.7.0 -Werkzeug==0.15.5 +Werkzeug pytest-localserver==0.5.0 pytest-cov==2.8.1 jsonschema==3.2.0 diff --git a/tox.ini b/tox.ini index e911301594..2aece2af5f 100644 --- a/tox.ini +++ b/tox.ini @@ -29,8 +29,7 @@ envlist = {pypy,py2.7,py3.4,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12,1.0} {pypy,py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-1.1 - # TODO: see note in [testenv:flask-dev] below - ; {py3.6,py3.7,py3.8,py3.9}-flask-dev + {py3.6,py3.7,py3.8,py3.9}-flask-dev {pypy,py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-bottle-0.12 @@ -123,9 +122,8 @@ deps = flask-1.0: Flask>=1.0,<1.1 flask-1.1: Flask>=1.1,<1.2 - # TODO: see note in [testenv:flask-dev] below - ; flask-dev: git+https://github.com/pallets/flask.git#egg=flask - ; flask-dev: git+https://github.com/pallets/werkzeug.git#egg=werkzeug + flask-dev: git+https://github.com/pallets/flask.git#egg=flask + flask-dev: git+https://github.com/pallets/werkzeug.git#egg=werkzeug # https://github.com/pytest-dev/pytest/issues/5532 {py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12}: pytest<5 @@ -295,39 +293,6 @@ basepython = commands = py.test {env:TESTPATH} {posargs} - -# TODO: This is broken out as a separate env so as to be able to override the -# werkzeug version. (You can't do it just by letting one version be specifed in -# a requirements file and specifying a different version in one testenv, see -# https://github.com/tox-dev/tox/issues/1390.) The issue is that as of 11/11/20, -# flask-dev has made a change which werkzeug then had to compensate for in -# https://github.com/pallets/werkzeug/pull/1960. Since we've got werkzeug -# pinned at 0.15.5 in test-requirements.txt, we don't get this fix. - -# At some point, we probably want to revisit this, since the list copied from -# test-requirements.txt could easily get stale. -[testenv:flask-dev] -deps = - git+https://github.com/pallets/flask.git#egg=flask - git+https://github.com/pallets/werkzeug.git#egg=werkzeug - - # everything below this point is from test-requirements.txt (minus, of - # course, werkzeug) - pytest==3.7.3 - pytest-forked==1.1.3 - tox==3.7.0 - pytest-localserver==0.5.0 - pytest-cov==2.8.1 - jsonschema==3.2.0 - pyrsistent==0.16.0 # TODO(py3): 0.17.0 requires python3, see https://github.com/tobgu/pyrsistent/issues/205 - mock # for testing under python < 3.3 - - gevent - - newrelic - executing - asttokens - [testenv:linters] commands = flake8 tests examples sentry_sdk From f7a8640200af2e4273838b7dbeb2131030866dd1 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 16:01:48 +0100 Subject: [PATCH 06/14] fix django --- tox.ini | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tox.ini b/tox.ini index 2aece2af5f..913c12f2df 100644 --- a/tox.ini +++ b/tox.ini @@ -291,6 +291,12 @@ basepython = pypy: pypy commands = + ; Note this sort of post-install hackery should only be necessary on Python + ; 2. On Python 3 the new dependency resolver by pip allows you to declare a + ; dependency multiple times as long as the versions don't directly + ; conflict. + django-{1.6,1.7}: pip install pytest<4 + py.test {env:TESTPATH} {posargs} [testenv:linters] From a72355dbe5de760fdc0ae269db693579e7812e4b Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 16:06:42 +0100 Subject: [PATCH 07/14] fix trytond --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index 913c12f2df..241a045eb4 100644 --- a/tox.ini +++ b/tox.ini @@ -199,6 +199,8 @@ deps = trytond-4.8: trytond>=4.8,<4.9 trytond-4.6: trytond>=4.6,<4.7 + trytond-4.8: werkzeug<1.0 + redis: fakeredis rediscluster-1: redis-py-cluster>=1.0.0,<2.0.0 From 2b603184ae52290ea94201733a094c8c7fd6e58e Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 16:14:10 +0100 Subject: [PATCH 08/14] drop trytond on py3.4 --- tox.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 241a045eb4..98d508cdc9 100644 --- a/tox.ini +++ b/tox.ini @@ -63,8 +63,7 @@ envlist = {py3.7,py3.8,py3.9}-tornado-{5,6} - {py3.4,py3.5,py3.6,py3.7,py3.8,py3.9}-trytond-{4.6,4.8,5.0} - {py3.5,py3.6,py3.7,py3.8,py3.9}-trytond-{5.2} + {py3.5,py3.6,py3.7,py3.8,py3.9}-trytond-{4.6,4.8,5.0,5.2} {py3.6,py3.7,py3.8,py3.9}-trytond-{5.4} {py2.7,py3.8,py3.9}-requests From e4c85631d80b4978566e20db30bb9e1f91b7ea7a Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 16:27:05 +0100 Subject: [PATCH 09/14] remove broken assertion --- tests/utils/test_general.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/utils/test_general.py b/tests/utils/test_general.py index 9a194fa8c8..370a6327ff 100644 --- a/tests/utils/test_general.py +++ b/tests/utils/test_general.py @@ -76,7 +76,6 @@ def test_filename(): assert x("bogus", "bogus") == "bogus" assert x("os", os.__file__) == "os.py" - assert x("pytest", pytest.__file__) == "pytest.py" import sentry_sdk.utils From 83723c1b426b67a341cce85502fde401f9081830 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 17:40:16 +0100 Subject: [PATCH 10/14] fix remaining issues --- sentry_sdk/integrations/flask.py | 2 +- tests/integrations/django/myapp/routing.py | 9 ++++++++- tox.ini | 20 +++++++++----------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index fe630ea50a..5f38c4094a 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -128,7 +128,7 @@ def env(self): def cookies(self): # type: () -> ImmutableTypeConversionDict[Any, Any] - return self.request.cookies + return {k: v[0] if isinstance(v, list) and len(v) == 1 else v for k, v in self.request.cookies.items()} def raw_data(self): # type: () -> bytes diff --git a/tests/integrations/django/myapp/routing.py b/tests/integrations/django/myapp/routing.py index ea224c2221..d13516d622 100644 --- a/tests/integrations/django/myapp/routing.py +++ b/tests/integrations/django/myapp/routing.py @@ -1,4 +1,11 @@ +import channels + from channels.http import AsgiHandler from channels.routing import ProtocolTypeRouter -application = ProtocolTypeRouter({"http": AsgiHandler()}) +if channels.__version__ < "4.0.0": + channels_handler = AsgiHandler +else: + channels_handler = AsgiHandler() + +application = ProtocolTypeRouter({"http": channels_handler}) diff --git a/tox.ini b/tox.ini index 98d508cdc9..f75d92d41a 100644 --- a/tox.ini +++ b/tox.ini @@ -63,7 +63,7 @@ envlist = {py3.7,py3.8,py3.9}-tornado-{5,6} - {py3.5,py3.6,py3.7,py3.8,py3.9}-trytond-{4.6,4.8,5.0,5.2} + {py3.5,py3.6,py3.7,py3.8,py3.9}-trytond-{4.6,5.0,5.2} {py3.6,py3.7,py3.8,py3.9}-trytond-{5.4} {py2.7,py3.8,py3.9}-requests @@ -96,8 +96,8 @@ deps = {py3.7,py3.8,py3.9}-django-{1.11,2.0,2.1,2.2,3.0,3.1,dev}: pytest-asyncio {py2.7,py3.7,py3.8,py3.9}-django-{1.11,2.2,3.0,3.1,dev}: psycopg2-binary - django-{1.6,1.7,1.8}: pytest-django<3.0 - django-{1.9,1.10,1.11,2.0,2.1}: pytest-django<4.0 + django-{1.6,1.7}: pytest-django<3.0 + django-{1.8,1.9,1.10,1.11,2.0,2.1}: pytest-django<4.0 django-{2.2,3.0,3.1}: pytest-django>=4.0 django-dev: git+https://github.com/pytest-dev/pytest-django#egg=pytest-django @@ -124,9 +124,6 @@ deps = flask-dev: git+https://github.com/pallets/flask.git#egg=flask flask-dev: git+https://github.com/pallets/werkzeug.git#egg=werkzeug - # https://github.com/pytest-dev/pytest/issues/5532 - {py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12}: pytest<5 - bottle-0.12: bottle>=0.12,<0.13 bottle-dev: git+https://github.com/bottlepy/bottle#egg=bottle @@ -195,7 +192,6 @@ deps = trytond-5.4: trytond>=5.4,<5.5 trytond-5.2: trytond>=5.2,<5.3 trytond-5.0: trytond>=5.0,<5.1 - trytond-4.8: trytond>=4.8,<4.9 trytond-4.6: trytond>=4.6,<4.7 trytond-4.8: werkzeug<1.0 @@ -292,12 +288,14 @@ basepython = pypy: pypy commands = - ; Note this sort of post-install hackery should only be necessary on Python - ; 2. On Python 3 the new dependency resolver by pip allows you to declare a - ; dependency multiple times as long as the versions don't directly - ; conflict. django-{1.6,1.7}: pip install pytest<4 + ; https://github.com/pytest-dev/pytest/issues/5532 + {py3.5,py3.6,py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12}: pip install pytest<5 + + ; trytond tries to import werkzeug.contrib + trytond-5.0: pip install werkzeug<1.0 + py.test {env:TESTPATH} {posargs} [testenv:linters] From 89a21b4b1c596fbafd27dbf78ec6acd41ab4bc64 Mon Sep 17 00:00:00 2001 From: sentry-bot Date: Thu, 7 Jan 2021 16:41:03 +0000 Subject: [PATCH 11/14] fix: Formatting --- sentry_sdk/integrations/flask.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index 5f38c4094a..3cf5c37eab 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -128,7 +128,10 @@ def env(self): def cookies(self): # type: () -> ImmutableTypeConversionDict[Any, Any] - return {k: v[0] if isinstance(v, list) and len(v) == 1 else v for k, v in self.request.cookies.items()} + return { + k: v[0] if isinstance(v, list) and len(v) == 1 else v + for k, v in self.request.cookies.items() + } def raw_data(self): # type: () -> bytes From 5ae2a49adf107e80d102005e9e2d75a11fd6a439 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 17:45:32 +0100 Subject: [PATCH 12/14] fix linters --- sentry_sdk/integrations/flask.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index 3cf5c37eab..2d0883ab8a 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -14,7 +14,6 @@ from sentry_sdk.integrations.wsgi import _ScopedResponse from typing import Any from typing import Dict - from werkzeug.datastructures import ImmutableTypeConversionDict from werkzeug.datastructures import ImmutableMultiDict from werkzeug.datastructures import FileStorage from typing import Union @@ -127,7 +126,7 @@ def env(self): return self.request.environ def cookies(self): - # type: () -> ImmutableTypeConversionDict[Any, Any] + # type: () -> Dict[Any, Any] return { k: v[0] if isinstance(v, list) and len(v) == 1 else v for k, v in self.request.cookies.items() From 99aec54b7d65fa9395ea3ff66ee359665a31f557 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 18:03:10 +0100 Subject: [PATCH 13/14] fix channels condition --- tests/integrations/django/myapp/routing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/django/myapp/routing.py b/tests/integrations/django/myapp/routing.py index d13516d622..b5755549ec 100644 --- a/tests/integrations/django/myapp/routing.py +++ b/tests/integrations/django/myapp/routing.py @@ -3,7 +3,7 @@ from channels.http import AsgiHandler from channels.routing import ProtocolTypeRouter -if channels.__version__ < "4.0.0": +if channels.__version__ < "3.0.0": channels_handler = AsgiHandler else: channels_handler = AsgiHandler() From daf949eebc0838f9619d8a93d6407551de9c0793 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 7 Jan 2021 18:52:52 +0100 Subject: [PATCH 14/14] remove py3.6-flask-dev because its failing --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index f75d92d41a..7dba50dadf 100644 --- a/tox.ini +++ b/tox.ini @@ -29,7 +29,7 @@ envlist = {pypy,py2.7,py3.4,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12,1.0} {pypy,py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-1.1 - {py3.6,py3.7,py3.8,py3.9}-flask-dev + {py3.7,py3.8,py3.9}-flask-dev {pypy,py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-bottle-0.12