Skip to content

Incompatible with fastapi>=0.95? #258

@fabcor-maxiv

Description

@fabcor-maxiv

Is the code incompatible with fastapi>=0.95?

When starting the application with fastapi==0.100.0, we get errors like the following one:

INFO:     | 2023-07-25 16:42:38 | pyispyb.core.routes | Importing proposals.py
ERROR:    | 2023-07-25 16:42:38 | pyispyb.core.routes | Could not import module `proposals.py`
Traceback (most recent call last):
  File "/home/fabcor/workspace/kits-ims/ispyb/py-ispyb/pyispyb/core/routes/__init__.py", line 37, in init_app
    module = import_module(".%s" % module_name[:-3], package=__name__)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/fabcor/workspace/kits-ims/ispyb/py-ispyb/pyispyb/core/routes/proposals.py", line 26, in <module>
    @router.get(
     ^^^^^^^^^^^
  File "/home/fabcor/workspace/kits-ims/ispyb/py-ispyb/.tox/dev/lib/python3.11/site-packages/fastapi/routing.py", line 706, in decorator
    self.add_api_route(
  File "/home/fabcor/workspace/kits-ims/ispyb/py-ispyb/.tox/dev/lib/python3.11/site-packages/fastapi/routing.py", line 645, in add_api_route
    route = route_class(
            ^^^^^^^^^^^^
  File "/home/fabcor/workspace/kits-ims/ispyb/py-ispyb/.tox/dev/lib/python3.11/site-packages/fastapi/routing.py", line 491, in __init__
    self.dependant = get_dependant(path=self.path_format, call=self.endpoint)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fabcor/workspace/kits-ims/ispyb/py-ispyb/.tox/dev/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 268, in get_dependant
    sub_dependant = get_param_sub_dependant(
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fabcor/workspace/kits-ims/ispyb/py-ispyb/.tox/dev/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 111, in get_param_sub_dependant
    return get_sub_dependant(
           ^^^^^^^^^^^^^^^^^^
  File "/home/fabcor/workspace/kits-ims/ispyb/py-ispyb/.tox/dev/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 147, in get_sub_dependant
    sub_dependant = get_dependant(
                    ^^^^^^^^^^^^^^
  File "/home/fabcor/workspace/kits-ims/ispyb/py-ispyb/.tox/dev/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 261, in get_dependant
    type_annotation, depends, param_field = analyze_param(
                                            ^^^^^^^^^^^^^^
  File "/home/fabcor/workspace/kits-ims/ispyb/py-ispyb/.tox/dev/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 410, in analyze_param
    assert isinstance(field_info, params.Path), (
AssertionError: Cannot use `Query` for path param 'proposal'

We found this fastapi ticket. Which leads us to assume that the application as it is written now is not compatible with fastapi>=0.95. And indeed after downgrading fastapi with a command like python -m pip install 'fastapi<0.95' the errors disappear.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions