You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pybrake raises deprecation warnings when used with the FastAPI middleware:
pybrake/middleware/fastapi.py:1: DeprecationWarning: ExceptionMiddleware is deprecated on `starlette.exceptions`. Import it from `starlette.middleware.exceptions` instead.
from .starlette import init_pybrake
pybrake/notifier.py:394: DeprecationWarning: Accessing attr.__version__ is deprecated and will be removed in a future release. Use importlib.metadata directly to query for attrs's packaging metadata.
if hasattr(mod, "__version__"):
pybrake/notifier.py:395: DeprecationWarning: Accessing attr.__version__ is deprecated and will be removed in a future release. Use importlib.metadata directly to query for attrs's packaging metadata.
versions[name] = mod.__version__
We can apply the patch like below to address this warning until pybrake provides a fix in future updates.
import importlib.metadata
import sys
from typing import Any, Dict
import pybrake.notifier
def get_version(name: str) -> str:
"""Get version using importlib.metadata."""
return importlib.metadata.version(name)
def patched_build_context(self: Any) -> Dict[str, Any]:
"""Patched version of pybrake.notifier.Notifier._build_context."""
ctx = self._context.copy() # pylint: disable=W0212
versions = ctx["versions"]
for name, _ in sys.modules.items():
if name.startswith("_"):
continue
try:
# Use importlib.metadata.version to get the version of the module
versions[name] = get_version(name)
except importlib.metadata.PackageNotFoundError as exc:
print(f"Failed to get version for {name}. Error: {str(exc)}")
versions[name] = None
return ctx
def apply_pybrake_patch() -> None:
"""Apply the monkey patch to the pybrake.notifier module."""
pybrake.notifier.Notifier._build_context = patched_build_context # pylint: disable=W0212
Hi team,
Pybrake raises deprecation warnings when used with the FastAPI middleware:
I am using the following versions:
The text was updated successfully, but these errors were encountered: