ISE on any request

Bug #1970557 reported by Pavel Francírek
52
This bug affects 9 people
Affects Status Importance Assigned to Milestone
fastapi (Ubuntu)
Confirmed
Undecided
Unassigned
Jammy
Fix Released
Undecided
Unassigned

Bug Description

[ Impact ]

The package can't be used at all in its current state because it doesn't work with one of its central dependencies. It creates a backtrace as seen in the original bug description on simple usage cases.

The bugfix makes the package compatible with the newer version of the dependency.

[ Test Plan ]

See the example code in the bug description, but for convenience I paste it here again:

Create a file "fastapi-test.py" with the following code:

-----
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"Status": "ok"}
-----

Then run that file with python interpreter.

[ Where problems could occur ]

The package isn't usable at all right now. It can't get worse than that, frankly speaking.

[Other info]
$ lsb_release -rd
Description: Ubuntu 22.04 LTS
Release: 22.04

$ apt-cache policy python3-fastapi
python3-fastapi:
  Installed: 0.63.0-2
  Candidate: 0.63.0-2
  Version table:
 *** 0.63.0-2 500
        500 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
        100 /var/lib/dpkg/status

Example:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"Status": "ok"}

Traceback:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/uvicorn/protocols/http/h11_impl.py", line 373, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/usr/lib/python3/dist-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "/usr/lib/python3/dist-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/lib/python3/dist-packages/starlette/applications.py", line 119, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/lib/python3/dist-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc
  File "/usr/lib/python3/dist-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/usr/lib/python3/dist-packages/starlette/exceptions.py", line 87, in __call__
    raise exc
  File "/usr/lib/python3/dist-packages/starlette/exceptions.py", line 76, in __call__
    await self.app(scope, receive, sender)
  File "/usr/lib/python3/dist-packages/starlette/routing.py", line 659, in __call__
    await route.handle(scope, receive, send)
  File "/usr/lib/python3/dist-packages/starlette/routing.py", line 259, in handle
    await self.app(scope, receive, send)
  File "/usr/lib/python3/dist-packages/starlette/routing.py", line 61, in app
    response = await func(request)
  File "/usr/lib/python3/dist-packages/fastapi/routing.py", line 191, in app
    solved_result = await solve_dependencies(
  File "/usr/lib/python3/dist-packages/fastapi/dependencies/utils.py", line 483, in solve_dependencies
    response = response or Response(
  File "/usr/lib/python3/dist-packages/starlette/responses.py", line 50, in __init__
    self.init_headers(headers)
  File "/usr/lib/python3/dist-packages/starlette/responses.py", line 77, in init_headers
    and not (self.status_code < 200 or self.status_code in (204, 304))
TypeError: '<' not supported between instances of 'NoneType' and 'int'

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in fastapi (Ubuntu):
status: New → Confirmed
Revision history for this message
Luca Della Vedova (luca-osrf) wrote :

I'm also encountering this issue, I probed a bit and noticed that the issue seems to be related to a mismatch between the fastapi version that is shipped in Ubuntu (0.63.0) and the starlette version (0.18.0).

As of changelog, officially fastapi started supporting starlette 0.18.0 only as of 0.76.0 (i.e. here https://fastapi.tiangolo.com/release-notes/#0760). For fastapi 0.63.0 the starlette requirement is 0.13.6 (i.e. here https://github.com/tiangolo/fastapi/blob/0.63.0/pyproject.toml#L35)

There also seem to be issues with uvicorn, for example fastapi 0.63.0 depends on uvicorn between 0.12.0 and 0.14.0 (i.e. here https://github.com/tiangolo/fastapi/blob/0.63.0/pyproject.toml#L93) but the system installed version is 0.15.0.

Bumping fastapi to a newer version should fix the package, as the bug above it can't really be used right now

Revision history for this message
Enrique (enrique-garcia) wrote :

I also confirm that this bug renders the current installation of fastapi in Ubuntu 22.04 unusable. I have used a virtual environment to install a new version of fastapi while using the rest of the packages from the system as follows:

# python3 -m venv --system-site-packages
# pip install fastapi==0.76

I then have tested that with the following self-contained test works fine:
import requests

import threading
import unittest
from time import sleep
import uvicorn.server

from fastapi import FastAPI

app = FastAPI()

@app.get("/ping")
def get_object() :
    return {"ping": "OK"}

class FastAPITest(unittest.TestCase):
    server: uvicorn.server.Server = None

    def __init__(self, args):
        super().__init__(args)

    @classmethod
    def setUpClass(cls):
        from uvicorn.config import Config
        from uvicorn import Server
        uvicorn_config = Config(app, port=8888, host="localhost")
        FastAPITest.server = Server(config=uvicorn_config)
        threading.Thread(target=FastAPITest.server.run).start()
        sleep(1)

    @classmethod
    def tearDownClass(cls):
        FastAPITest.server.should_exit = True
        sleep(1)

    def test_ping(self):
        requests.get("http://localhost:8888/ping")

As previous comment said, version 0.76 of fastapi would be compatible with the installed versions of both starlette and uvicorn and will solve the issue.

Changed in fastapi (Ubuntu):
assignee: nobody → Enrique (enrique-garcia)
assignee: Enrique (enrique-garcia) → nobody
Revision history for this message
Enrique (enrique-garcia) wrote :

@Sandro Tosi: I have subscribed you to this bug since you seem to be the maintainer of the package. My apologies if that's not the case.

Revision history for this message
Sandro Tosi (morph-debian) wrote :

i maintain fastapi for debian, not for ubuntu, so i'm not the right person to ask/escalate issues to.

Revision history for this message
Enrique (enrique-garcia) wrote :

Thank you Sandro for the answer.
In the meantime I see that Ubuntu 22.10 which ships python3-fastapi 0.74.1-1 while using the same versions of python3-starlette and python3-uvicorn as Ubuntu 22.04 is working properly. So I guess that the minimum effort would be to also ship python3-fastapi 0.74.1-1 in Ubuntu 22.04.

Revision history for this message
Rhonda D'Vine (rhonda) wrote :

I've prepared a SRU for this bug. It contains two upstream commits that make the package work with the starlette version in jammy. All the information from the SRU template are already answered above, so I am not copying them here again.

tags: added: patch
Revision history for this message
Enrique (enrique-garcia) wrote :

Thank you very much Rhonda for this SRU. I can help with testing, but I am afraid I don't know how to test your changes. Is there a deb package somewhere that can be installed?

Thank you!

Revision history for this message
Rhonda D'Vine (rhonda) wrote :

Thanks Enrique. I tried to follow the SRU guide lines but my upload was rejected, and I am unsure what the reason for that was because the errors I get were confusing. Source-only upload got a reject message "Mismatch in binaryfullness", but with the binary package included dput didn't allow me to upload at all. I'm still trying to figure this out.

Revision history for this message
Timo Aaltonen (tjaalton) wrote :

this bug is missing the SRU information from the description

Steve Langasek (vorlon)
Changed in fastapi (Ubuntu):
status: Confirmed → Incomplete
Revision history for this message
Rhonda D'Vine (rhonda) wrote :

Timo, can you please elaborate what is missing? Because it's there. If you are just referring that it doesn't use the template then ... sorry to not followed the bureocratic bits to the detail, I'll do that now. I can though understand that not having done that directly would have left more work on your shoulders, I was under the impression that all bits are already in here (and it's not like there are hundreds of comments, so ...)

[ Impact ]

The package can't be used at all in its current state because it doesn't work with one of its central dependencies. It creates a backtrace as seen in the original bug description on simple usage cases.

The bugfix makes the package compatible with the newer version of the dependency.

[ Test Plan ]

 * detailed instructions how to reproduce the bug

See the example code in the bug description, but for convenience I paste it here again:

Create a file "fastapi-test.py" with the following code:

-----
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"Status": "ok"}
-----

Then run that file with python interpreter.

[ Where problems could occur ]

 * Think about what the upload changes in the software. Imagine the change is
   wrong or breaks something else: how would this show up?

The package isn't usable at all right now. It can't get worse than that, frankly speaking.

 * This must '''never''' be "None" or "Low", or entirely an argument as to why
   your upload is low risk.

Well, actually what regression risk could there be for a package not usable at all right now? I would very much assert that this covers a clear "None" because even if the fix wouldn't work (which it does) the package still would just not work and couldn't be in a worse state.

[ Other Info ]

 * Anything else you think is useful to include

I really thought the bug description and the description of the patch should be self-explenatory, and I'm sorry that this assumption seemingly was wrong. My bad.

Changed in fastapi (Ubuntu):
status: Incomplete → Confirmed
Steve Langasek (vorlon)
description: updated
Revision history for this message
Steve Langasek (vorlon) wrote : Please test proposed package

Hello Pavel, or anyone else affected,

Accepted fastapi into jammy-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/fastapi/0.63.0-2ubuntu0.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-jammy to verification-done-jammy. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-jammy. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in fastapi (Ubuntu Jammy):
status: New → Fix Committed
tags: added: verification-needed verification-needed-jammy
Revision history for this message
Enrique (enrique-garcia) wrote :

I have tried with one application that uses fastapi and it seems it is working fine. I have not tested it thoroughly but at least calling a couple of API methods is working fine.
Thank you very much for fixing this!

Revision history for this message
Kamil M (kamil-certat) wrote :

Hi, I have confirmed that the change works as I expected. I have tested it in combination with IntelMQ software by:

1. first installing it with the default python3-fastapi (0.63.0-2), result: no API endpoint is able to work, errors as in this bug report;
2. then enabling the -proposed repository, installing just the new version of python3-fastapi (0.63.0-2ubuntu0.1) and restarting affected software. Result: API is working, no errors.

Test performed on Ubuntu 22.04 after installing all available upgrades.

@vorlon I'd like to change the tag, but it looks I don't have enough rights to do so. Could you please update the tag to verification-done-jammy?

Rhonda D'Vine (rhonda)
tags: added: verification-done-jammy
removed: verification-needed-jammy
tags: added: verification-done verification-needed-jammy
removed: verification-done-jammy verification-needed
tags: added: verification-done-jammy
removed: verification-needed-jammy
Revision history for this message
Sebastian Wagner (sebix) wrote :

The changelog says:

+ * Add upstream commits 33d614 and 11d0a0 to make it work with
+ starlette 1.18.0 which we have in jammy (LP: #1970557)

You mean starlette 0.18.0

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package fastapi - 0.63.0-2ubuntu0.1

---------------
fastapi (0.63.0-2ubuntu0.1) jammy; urgency=low

  * Add upstream commits 33d614 and 11d0a0 to make it work with
    starlette 1.18.0 which we have in jammy (LP: #1970557)

 -- Rhonda D'Vine <email address hidden> Wed, 19 Jul 2023 14:37:34 +0000

Changed in fastapi (Ubuntu Jammy):
status: Fix Committed → Fix Released
Revision history for this message
Chris Halse Rogers (raof) wrote : Update Released

The verification of the Stable Release Update for fastapi has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.