Skip to content

fix(flask): stop reading deprecated flask.__version__#4422

Open
alliasgher wants to merge 2 commits intoopen-telemetry:mainfrom
alliasgher:fix-flask-deprecated-version-attr
Open

fix(flask): stop reading deprecated flask.__version__#4422
alliasgher wants to merge 2 commits intoopen-telemetry:mainfrom
alliasgher:fix-flask-deprecated-version-attr

Conversation

@alliasgher
Copy link
Copy Markdown

Description

Flask 3.1 deprecated the module-level flask.__version__ attribute and emits a DeprecationWarning on access; 3.2 will remove it. The Flask instrumentor was hitting that warning at import time via:

_IS_FLASK_31_PLUS = hasattr(flask, "__version__") and package_version.parse(
    flask.__version__
) >= package_version.parse("3.1.0")

even though it already computes the installed Flask version via importlib.metadata.version("flask") a few lines below. Use that flask_version for the 3.1+ check and drop the deprecated attribute access entirely.

Fixes #4402

Test plan

  • Existing unit tests exercise both Flask 2.x and 3.x+ paths.
  • No behavioural change in _IS_FLASK_31_PLUS — just a different, non-deprecated source for the version string.

Signed-off-by: Ali alliasgher123@gmail.com

Flask 3.1 deprecated the module-level __version__ attribute and emits a
DeprecationWarning on access; 3.2 will remove it. The Flask
instrumentor was hitting that warning at import time via

    _IS_FLASK_31_PLUS = hasattr(flask, "__version__") and
        package_version.parse(flask.__version__) >= package_version.parse("3.1.0")

even though it already computes the installed Flask version via
importlib.metadata.version("flask") a few lines below. Use that
flask_version for the 3.1+ check and drop the deprecated attribute
access entirely.

Fixes open-telemetry#4402

Signed-off-by: Ali <alliasgher123@gmail.com>
@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Thank you for this @alliasgher . Please could you run tox -e precommit and commit the formatting fixes.

@tammy-baylis-swi tammy-baylis-swi moved this to Reviewed PRs that need fixes in Python PR digest Apr 14, 2026
Signed-off-by: alliasgher <alliasgher123@gmail.com>
@alliasgher
Copy link
Copy Markdown
Author

Done, ran tox -e precommit and committed the ruff formatting fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

flask.__version__ is deprecated

2 participants