Closed willarmiros closed 11 months ago
Turns out this was an issue with upgrading the FastAPI version. In FastAPI v0.91.0, they switched the middleware initialization logic to be lazily initialized on the first server request: https://fastapi.tiangolo.com/release-notes/#0910
Because our script had no server request, the middleware was never initialized and we got this error. To fix, you can simply manually instantiate the middleware:
app = FastAPI()
DBSessionMiddleware(app, databaseUrl)
I am using fastapi-sqlalchemy for a project that also uses Pydantic to define API object models. We recently upgraded to Pydantic 2.x, and our application works fine except for one instance where we use the
db
object outside of a route, to seed our Database.The version upgrades were:
The code where we're using fastapi-sqlalchemy looks like:
The command we use to run the database seeding python script is:
And the stacktrace we're getting is:
Anyone else experiencing anything similar? Given there hasn't been a release in ~3 years, is it just time to move on from the library?