Skip to content

flask.__version__ is deprecated #4402

@davidism

Description

@davidism

Describe your environment

OS: Any
Python version: Any
Package version: 0.61b0

What happened?

The flask.__version__ attribute is deprecated and will be removed, it raises a DeprecationWarning on access.

.tox/tests/lib/python3.14/site-packages/app/telemetry.py:9: in <module>
    from opentelemetry.instrumentation.flask import FlaskInstrumentor
.tox/tests/lib/python3.14/site-packages/opentelemetry/instrumentation/flask/__init__.py:306: in <module>
    _IS_FLASK_31_PLUS = hasattr(flask, "__version__") and package_version.parse(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/tests/lib/python3.14/site-packages/flask/__init__.py:52: in __getattr__
    warnings.warn(
DeprecationWarning: The '__version__' attribute is deprecated and will be removed in Flask 3.2. Use feature detection or 'importlib.metadata.version("flask")' instead.

Steps to Reproduce

from opentelemetry.instrumentation.flask import FlaskInstrumentor

Expected Result

No deprecation warning is emitted.

Actual Result

A deprecation warning is emitted.

Additional context

The code that causes this was added recently in #3938:

# Global constants for Flask 3.1+ streaming context cleanup
_IS_FLASK_31_PLUS = hasattr(flask, "__version__") and package_version.parse(
flask.__version__
) >= package_version.parse("3.1.0")

However, it ignores the existing flask_version attribute defined a few lines below, which was added to address this warning the first time it was reported:

The version 3.1 detection should be moved below this line, and use the existing metadata rather than trying to access flask.__version__ again.

Would you like to implement a fix?

None

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions