From 6048eca3640fc13136cbb65f4ac18a214a929f73 Mon Sep 17 00:00:00 2001 From: Vageeshan Date: Fri, 1 Sep 2023 04:34:34 -0700 Subject: [PATCH 1/6] Fixing deprecated version attribute --- sentry_sdk/integrations/flask.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index 61f2e315da..2d0ecbc56e 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from importlib.metadata import version from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.hub import Hub, _should_send_default_pii @@ -28,7 +29,6 @@ try: from flask import Flask, Request # type: ignore - from flask import __version__ as FLASK_VERSION from flask import request as flask_request from flask.signals import ( before_render_template, @@ -44,6 +44,7 @@ except ImportError: raise DidNotEnable("blinker is not installed") +FLASK_VERSION = version("flask") TRANSACTION_STYLE_VALUES = ("endpoint", "url") From 0891fe28cd64dac7e8fc1e94a36b7a5754f87017 Mon Sep 17 00:00:00 2001 From: Vageeshan Date: Mon, 4 Sep 2023 01:22:05 -0700 Subject: [PATCH 2/6] getting flask version from _get_installed_modules --- sentry_sdk/integrations/flask.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index 2d0ecbc56e..597a6f3a7b 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -1,11 +1,11 @@ from __future__ import absolute_import -from importlib.metadata import version from sentry_sdk._types import TYPE_CHECKING from sentry_sdk.hub import Hub, _should_send_default_pii from sentry_sdk.integrations import DidNotEnable, Integration from sentry_sdk.integrations._wsgi_common import RequestExtractor from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware +from sentry_sdk.integrations.modules import _get_installed_modules from sentry_sdk.scope import Scope from sentry_sdk.tracing import SOURCE_FOR_STYLE from sentry_sdk.utils import ( @@ -44,7 +44,8 @@ except ImportError: raise DidNotEnable("blinker is not installed") -FLASK_VERSION = version("flask") +installed_packages = _get_installed_modules() +FLASK_VERSION = installed_packages("flask") TRANSACTION_STYLE_VALUES = ("endpoint", "url") From 9fa946e48fd39b648da2eccf14da1ac1393850b2 Mon Sep 17 00:00:00 2001 From: Vageeshan Date: Tue, 5 Sep 2023 05:06:47 -0700 Subject: [PATCH 3/6] moving Flask version to setup_once --- sentry_sdk/integrations/flask.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index 597a6f3a7b..d00c490780 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -44,8 +44,7 @@ except ImportError: raise DidNotEnable("blinker is not installed") -installed_packages = _get_installed_modules() -FLASK_VERSION = installed_packages("flask") +FLASK_VERSION = None TRANSACTION_STYLE_VALUES = ("endpoint", "url") @@ -66,7 +65,10 @@ def __init__(self, transaction_style="endpoint"): @staticmethod def setup_once(): # type: () -> None + global FLASK_VERSION + installed_packages = _get_installed_modules() + FLASK_VERSION = installed_packages["flask"] version = parse_version(FLASK_VERSION) if version is None: From c900ee144bb0e84c2b44817c9f716e09556c2a6d Mon Sep 17 00:00:00 2001 From: Vageeshan Date: Tue, 5 Sep 2023 07:33:27 -0700 Subject: [PATCH 4/6] localizing FLASK_VERSION --- sentry_sdk/integrations/flask.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index d00c490780..d7c2c902f2 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -44,7 +44,6 @@ except ImportError: raise DidNotEnable("blinker is not installed") -FLASK_VERSION = None TRANSACTION_STYLE_VALUES = ("endpoint", "url") @@ -65,7 +64,6 @@ def __init__(self, transaction_style="endpoint"): @staticmethod def setup_once(): # type: () -> None - global FLASK_VERSION installed_packages = _get_installed_modules() FLASK_VERSION = installed_packages["flask"] From e09881316641890eb9a9f5274cbc5b1c44461fa2 Mon Sep 17 00:00:00 2001 From: Vageeshan Mankala <43883923+vagi8@users.noreply.github.com> Date: Wed, 6 Sep 2023 01:02:34 -0700 Subject: [PATCH 5/6] satisfying flake8 --- sentry_sdk/integrations/flask.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index d7c2c902f2..78d7019b67 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -66,8 +66,8 @@ def setup_once(): # type: () -> None installed_packages = _get_installed_modules() - FLASK_VERSION = installed_packages["flask"] - version = parse_version(FLASK_VERSION) + flask_version = installed_packages["flask"] + version = parse_version(flask_version) if version is None: raise DidNotEnable("Unparsable Flask version: {}".format(FLASK_VERSION)) From b3e65209997ba6181eb40849b27f9ee0dcd4ea16 Mon Sep 17 00:00:00 2001 From: Vageeshan Mankala <43883923+vagi8@users.noreply.github.com> Date: Wed, 6 Sep 2023 01:28:27 -0700 Subject: [PATCH 6/6] Update sentry_sdk/integrations/flask.py Co-authored-by: Ivana Kellyerova --- sentry_sdk/integrations/flask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index 78d7019b67..0da411c23d 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -70,7 +70,7 @@ def setup_once(): version = parse_version(flask_version) if version is None: - raise DidNotEnable("Unparsable Flask version: {}".format(FLASK_VERSION)) + raise DidNotEnable("Unparsable Flask version: {}".format(flask_version)) if version < (0, 10): raise DidNotEnable("Flask 0.10 or newer is required.")