InvalidRequestError: A transaction is already begun on this Session. #11196
-
I have a simple FastAPI app that connects to postgres using sqlalchemy + psycopg2
i'm trying to test the application and here is my test case
Why am I getting a transaction is already begun error? The error:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
the full stack trace is quite important to give context but we would assume your delete_app_by_user_id function is where the trace originates, since that's where there is an explicit call to session.begin(). if the session delivered by the well looking at your code if I had to guess I would say that since you have a single session used for everything, you are first calling into |
Beta Was this translation helpful? Give feedback.
the full stack trace is quite important to give context but we would assume your delete_app_by_user_id function is where the trace originates, since that's where there is an explicit call to session.begin(). if the session delivered by the
Session = Depends(get_database_session)
construct (this is a fastapi thing that we dont have information on) was already being used in a different method , then it would already be ongoing in a transaction and you can't call begin() on a session in that state.well looking at your code if I had to guess I would say that since you have a single session used for everything, you are first calling into
client.post("/api/v1/app-users", json=data)
which is go…