How can I roll back after a database error? · Issue #293 · graphql-python/graphene-sqlalchemy (original) (raw)
Hi, I am using this pattern: https://docs.graphene-python.org/projects/sqlalchemy/en/latest/tutorial/#defining-our-models
I noticed that when the database runs into an error, any further queries that want to use the same session are blocked.
E.g.:
- Have a postgres database with a table that has a date field and define queries.
- Now try to query the table and filter for the date.
- For the date, you accidentally enter an int (a year). You will run into an error like this:
sqlalchemy.exc.DataError: (psycopg2.errors.InvalidDatetimeFormat) invalid input syntax for type date: "2001"
- Now try a new query (correctly formed), you will get this error:
graphql.error.located_error.GraphQLLocatedError: (psycopg2.errors.InFailedSqlTransaction) current transaction is aborted, commands ignored until end of transaction block
The session is basically blocked and since the session management is hidden I dont know how to roll back the failed transaction from 3.