rollbar / pyrollbar

Error tracking and logging from Python to Rollbar
https://docs.rollbar.com/docs/python/
MIT License
213 stars 133 forks source link

FastAPI version validation needs improvements #432

Closed ayharano closed 10 months ago

ayharano commented 1 year ago

I was testing FastAPI 0.100.0-beta2 with Pydantic 2.0 released today and after a few adjustments, when I ran my test suite, it triggered an error due to https://github.com/rollbar/pyrollbar/blob/e3e159533dfec07ea0d7c2ec678267552db96bfb/rollbar/contrib/fastapi/utils.py#L31

I triggered ipdb just before that line and it failed because the displayed line does a string-based comparison, not a proper SemVer comparison

ipdb> self.min_version
'0.41.0'
ipdb> fastapi.__version__
'0.100.0-beta2'
ipdb> fastapi.__version__ < self.min_version  # due to lexicographic comparison, not proper SemVer comparison
True

This issue will be perceived as soon as FastAPI 0.100.0 version is released and projects with pyrollbar use an unpinned version of FastAPI.

cforcey commented 12 months ago

This is impacting us as well. Thanks @ayharano for reporting it.

josephgruber commented 11 months ago

I can confirm this does manifest itself with FastAPI v0.100.0. Using the "add_to" method the following error is thrown:

rollbar.contrib.fastapi.utils.FastAPIVersionError: FastAPI 0.41.0+ is required to use add_to() function

Downgrading to FastAPI 0.99.1 resolves the error.

cforcey commented 11 months ago

Thanks @danielmorell for looking into this! This continues to block our upgrade path for fast-api 0.100+ versions.

johnchristopherjones commented 11 months ago

In rollbar.cotnrib.fastapi.utils, the following check appears:

            if fastapi.__version__ < self.min_version:

A robust quick fix is to use Version from PyPA's packaging, which is already a dependency of pytest.

from packaging.version import Version
...
            if Version(fastapi.__version__) < Version(self.min_version):

Or, since we know FastAPI uses PyPA-compatible versioning, we can be hacky:

            if fastapi.__version__.split(".", 2) < self.min_version.split(".", 2):
miska-ship-it commented 10 months ago

Any news on this? It is blocking all our projects from updating properly.

danielmorell commented 9 months ago

This was released in the v1.0.0 beta.

josephgruber commented 8 months ago

Any word when 1.0.0 will be released (non-beta)?

ghost commented 7 months ago

Hey @josephgruber, 1.0.0 is planned to be released in 1-2 weeks at latest.

danielmorell commented 7 months ago

Version 1.0.0 is out now!