sentry-python: SQLAlchemy integration fails to parse version `2.0.5.post1`

How do you use Sentry?

Self-hosted/on-premise

Version

1.16.0

Steps to Reproduce

Call sentry_sdk.init() with SQLAlchemy integration and install SQLAlchemy==2.0.5.post1.

Expected Result

Success.

Actual Result

  File "///src/.../__init__.py", line 150, in <module>
    sentry_sdk.init(
  File "///.tox/py/lib/python3.10/site-packages/sentry_sdk/hub.py", line 121, in _init
    client = Client(*args, **kwargs)  # type: ignore
  File "///.tox/py/lib/python3.10/site-packages/sentry_sdk/client.py", line 117, in __init__
    self._init_impl()
  File "///.tox/py/lib/python3.10/site-packages/sentry_sdk/client.py", line 151, in _init_impl
    self.integrations = setup_integrations(
  File "///.tox/py/lib/python3.10/site-packages/sentry_sdk/integrations/__init__.py", line 124, in setup_integrations
    type(integration).setup_once()
  File "///.tox/py/lib/python3.10/site-packages/sentry_sdk/integrations/sqlalchemy.py", line 37, in setup_once
    raise DidNotEnable(
sentry_sdk.integrations.DidNotEnable: Unparsable SQLAlchemy version: 2.0.5.post1

This is very similar to https://github.com/getsentry/sentry-python/issues/1811, which was fixed in #1812 but that doesn’t handle all the possible PEP440 variations, [N!]N(.N)*[{a|b|rc}N][.postN][.devN]

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 12
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I mean unless you’ve fixed it, this will break the moment SQLAlchemy (or probably any other dependency like that?) releases version with a tag?

You can upgrade to 2.0.6 and remove the pin

The real question is why you don’t set up Sentry in your tests. If you don’t provide a token, it will set up but not report. That’s how I found out about it.

because I didn’t know about that! thanks ^^

The real question is why you don’t set up Sentry in your tests. If you don’t provide a token, it will set up but not report. That’s how I found out about it.

I extremely prefer a crash over a silently disabled error reporting.

The version parsing in the other integrations is equally brittle in relation to PEP 440. It’s probably best to use the regular expression provided in the PEP and parse the release group:

VERSION_PATTERN = r"""
    v?
    (?:
        (?:(?P<epoch>[0-9]+)!)?                           # epoch
        (?P<release>[0-9]+(?:\.[0-9]+)*)                  # release segment
        (?P<pre>                                          # pre-release
            [-_\.]?
            (?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
            [-_\.]?
            (?P<pre_n>[0-9]+)?
        )?
        (?P<post>                                         # post release
            (?:-(?P<post_n1>[0-9]+))
            |
            (?:
                [-_\.]?
                (?P<post_l>post|rev|r)
                [-_\.]?
                (?P<post_n2>[0-9]+)?
            )
        )?
        (?P<dev>                                          # dev release
            [-_\.]?
            (?P<dev_l>dev)
            [-_\.]?
            (?P<dev_n>[0-9]+)?
        )?
    )
    (?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))?       # local version
"""

_regex = re.compile(
    r"^\s*" + VERSION_PATTERN + r"\s*$",
    re.VERBOSE | re.IGNORECASE,
)

Alternatively packaging.version or parver would work (probably not worth adding a dependency here).