From d475c1bc0650b26bd4b2e6ed4bb84a464753ba76 Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Tue, 14 Nov 2023 14:50:38 +0100 Subject: [PATCH 1/6] Test with Flask 3.0 --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index 072b561b07..bc2bcbb084 100644 --- a/tox.ini +++ b/tox.ini @@ -95,6 +95,7 @@ envlist = {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-v{0.11,0.12,1.0} {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-flask-v{1.1} {py3.6,py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.0} + {py3.10,py3.11,py3.12}-flask-v{3.0} # Gevent {py2.7,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-gevent @@ -339,6 +340,7 @@ deps = flask-v1.0: Flask>=1.0,<1.1 flask-v1.1: Flask>=1.1,<1.2 flask-v2.0: Flask>=2.0,<2.1 + flask-v3.0: Flask>=3.0,<3.1 # Gevent # See http://www.gevent.org/install.html#older-versions-of-python From 655a4c80d3c9125f51912565d4f6aa1fc3369308 Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Tue, 14 Nov 2023 15:28:55 +0100 Subject: [PATCH 2/6] fix werkzeug version --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index bc2bcbb084..c38d60332c 100644 --- a/tox.ini +++ b/tox.ini @@ -334,7 +334,8 @@ deps = # Flask flask: flask-login - flask: Werkzeug<2.1.0 + flask-v{0.11,0.12,1.0,1.1,2.0}: Werkzeug<2.1.0 + flask-v{3.0}: Werkzeug flask-v0.11: Flask>=0.11,<0.12 flask-v0.12: Flask>=0.12,<0.13 flask-v1.0: Flask>=1.0,<1.1 From 22b95245d7a1ce6e6e89e656d21309c2a75cf863 Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Tue, 14 Nov 2023 16:04:39 +0100 Subject: [PATCH 3/6] things --- tests/integrations/flask/test_flask.py | 31 +++++++++++++++++++------- tox.ini | 6 ++--- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/integrations/flask/test_flask.py b/tests/integrations/flask/test_flask.py index 09b2c2fb30..c45b4084e8 100644 --- a/tests/integrations/flask/test_flask.py +++ b/tests/integrations/flask/test_flask.py @@ -1,10 +1,9 @@ import json import re -import pytest import logging - from io import BytesIO +import pytest from flask import ( Flask, Response, @@ -14,9 +13,10 @@ render_template_string, ) from flask.views import View - from flask_login import LoginManager, login_user +from werkzeug.wrappers.request import UnsupportedMediaType +import sentry_sdk.integrations.flask as flask_sentry from sentry_sdk import ( set_tag, configure_scope, @@ -26,7 +26,6 @@ Hub, ) from sentry_sdk.integrations.logging import LoggingIntegration -import sentry_sdk.integrations.flask as flask_sentry from sentry_sdk.serializer import MAX_DATABAG_BREADTH @@ -340,7 +339,11 @@ def test_flask_medium_formdata_request(sentry_init, capture_events, app): def index(): assert request.form["foo"] == data["foo"] assert not request.get_data() - assert not request.get_json() + try: + assert not request.get_json() + except UnsupportedMediaType: + # flask/werkzeug 3 + pass capture_message("hi") return "ok" @@ -372,7 +375,11 @@ def index(): assert request.form["username"] == data["username"] assert request.form["age"] == data["age"] assert not request.get_data() - assert not request.get_json() + try: + assert not request.get_json() + except UnsupportedMediaType: + # flask/werkzeug 3 + pass set_tag("view", "yes") capture_message("hi") return "ok" @@ -405,7 +412,11 @@ def index(): assert request.get_data() == data else: assert request.get_data() == data.encode("ascii") - assert not request.get_json() + try: + assert not request.get_json() + except UnsupportedMediaType: + # flask/werkzeug 3 + pass capture_message("hi") return "ok" @@ -431,7 +442,11 @@ def test_flask_files_and_form(sentry_init, capture_events, app): def index(): assert list(request.form) == ["foo"] assert list(request.files) == ["file"] - assert not request.get_json() + try: + assert not request.get_json() + except UnsupportedMediaType: + # flask/werkzeug 3 + pass capture_message("hi") return "ok" diff --git a/tox.ini b/tox.ini index c38d60332c..8b14d71d37 100644 --- a/tox.ini +++ b/tox.ini @@ -94,7 +94,7 @@ envlist = # Flask {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-v{0.11,0.12,1.0} {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-flask-v{1.1} - {py3.6,py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.0} + {py3.6,py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.3} {py3.10,py3.11,py3.12}-flask-v{3.0} # Gevent @@ -334,13 +334,13 @@ deps = # Flask flask: flask-login - flask-v{0.11,0.12,1.0,1.1,2.0}: Werkzeug<2.1.0 + flask-v{0.11,0.12,1.0,1.1,2.0,2.3}: Werkzeug<2.1.0 flask-v{3.0}: Werkzeug flask-v0.11: Flask>=0.11,<0.12 flask-v0.12: Flask>=0.12,<0.13 flask-v1.0: Flask>=1.0,<1.1 flask-v1.1: Flask>=1.1,<1.2 - flask-v2.0: Flask>=2.0,<2.1 + flask-v2.3: Flask>=2.3,<2.4 flask-v3.0: Flask>=3.0,<3.1 # Gevent From 11b08a2bec335a2bcf97e537b6c2b5e3855aea01 Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Tue, 14 Nov 2023 16:12:57 +0100 Subject: [PATCH 4/6] compat --- tests/integrations/flask/test_flask.py | 11 +++++++++-- tox.ini | 7 ++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/integrations/flask/test_flask.py b/tests/integrations/flask/test_flask.py index c45b4084e8..3d3572e2d3 100644 --- a/tests/integrations/flask/test_flask.py +++ b/tests/integrations/flask/test_flask.py @@ -14,7 +14,11 @@ ) from flask.views import View from flask_login import LoginManager, login_user -from werkzeug.wrappers.request import UnsupportedMediaType + +try: + from werkzeug.wrappers.request import UnsupportedMediaType +except ImportError: + UnsupportedMediaType = None import sentry_sdk.integrations.flask as flask_sentry from sentry_sdk import ( @@ -560,9 +564,12 @@ def test_cli_commands_raise(app): def foo(): 1 / 0 + def create_app(*_): + return app + with pytest.raises(ZeroDivisionError): app.cli.main( - args=["foo"], prog_name="myapp", obj=ScriptInfo(create_app=lambda _: app) + args=["foo"], prog_name="myapp", obj=ScriptInfo(create_app=create_app) ) diff --git a/tox.ini b/tox.ini index 8b14d71d37..add3640719 100644 --- a/tox.ini +++ b/tox.ini @@ -94,7 +94,7 @@ envlist = # Flask {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-v{0.11,0.12,1.0} {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-flask-v{1.1} - {py3.6,py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.3} + {py3.6,py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.0,2.3} {py3.10,py3.11,py3.12}-flask-v{3.0} # Gevent @@ -334,12 +334,13 @@ deps = # Flask flask: flask-login - flask-v{0.11,0.12,1.0,1.1,2.0,2.3}: Werkzeug<2.1.0 - flask-v{3.0}: Werkzeug + flask-v{0.11,0.12,1.0,1.1,2.0}: Werkzeug<2.1.0 + flask-v{2.3,3.0}: Werkzeug flask-v0.11: Flask>=0.11,<0.12 flask-v0.12: Flask>=0.12,<0.13 flask-v1.0: Flask>=1.0,<1.1 flask-v1.1: Flask>=1.1,<1.2 + flask-v2.0: Flask>=2.0,<2.1 flask-v2.3: Flask>=2.3,<2.4 flask-v3.0: Flask>=3.0,<3.1 From c2055bc28b9881522468af4ea0bd1e25f3334acb Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Tue, 14 Nov 2023 16:20:13 +0100 Subject: [PATCH 5/6] no 2.3 for py3.6 --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index add3640719..87d1402af9 100644 --- a/tox.ini +++ b/tox.ini @@ -94,7 +94,8 @@ envlist = # Flask {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-v{0.11,0.12,1.0} {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-flask-v{1.1} - {py3.6,py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.0,2.3} + {py3.6,py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.0} + {py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.3} {py3.10,py3.11,py3.12}-flask-v{3.0} # Gevent From 69141fcbf6ea25a35964ba10dbbcb76bffbd77a7 Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Tue, 14 Nov 2023 16:34:46 +0100 Subject: [PATCH 6/6] remove 2.3 again --- tox.ini | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 87d1402af9..c38d60332c 100644 --- a/tox.ini +++ b/tox.ini @@ -95,7 +95,6 @@ envlist = {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-v{0.11,0.12,1.0} {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-flask-v{1.1} {py3.6,py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.0} - {py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.3} {py3.10,py3.11,py3.12}-flask-v{3.0} # Gevent @@ -336,13 +335,12 @@ deps = # Flask flask: flask-login flask-v{0.11,0.12,1.0,1.1,2.0}: Werkzeug<2.1.0 - flask-v{2.3,3.0}: Werkzeug + flask-v{3.0}: Werkzeug flask-v0.11: Flask>=0.11,<0.12 flask-v0.12: Flask>=0.12,<0.13 flask-v1.0: Flask>=1.0,<1.1 flask-v1.1: Flask>=1.1,<1.2 flask-v2.0: Flask>=2.0,<2.1 - flask-v2.3: Flask>=2.3,<2.4 flask-v3.0: Flask>=3.0,<3.1 # Gevent