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.:

  1. Have a postgres database with a table that has a date field and define queries.
  2. Now try to query the table and filter for the date.
  3. 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"
  1. 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.