Browse Source

fix: use tuple comparison for python-multipart version check

String comparison is lexicographic, so "0.0.100" > "0.0.12" evaluates to
False ("1" < "9" by char code). A valid python-multipart==0.0.100+
installation was incorrectly rejected as too old, raising multipart_not_installed_error
on any Form() or File() endpoint.

Parse the version into an integer tuple before comparing so numeric ordering
is used instead.
pull/15556/head
Rishab Motgi 3 weeks ago
parent
commit
d8a04c782f
  1. 2
      fastapi/dependencies/utils.py

2
fastapi/dependencies/utils.py

@ -96,7 +96,7 @@ def ensure_multipart_is_installed() -> None:
from python_multipart import __version__
# Import an attribute that can be mocked/deleted in testing
assert __version__ > "0.0.12"
assert tuple(int(x) for x in __version__.split(".")[:3]) > (0, 0, 12)
except (ImportError, AssertionError):
try:
# __version__ is available in both multiparts, and can be mocked

Loading…
Cancel
Save