How can I roll back after a database error?
See original GitHub issueHi, 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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Rolling back transactions via the ROLLBACK SQL query
The article explains how to rollback SQL queries using transactions. Queries can be automatically or manually rolled back via transactions.
Read more >Roll Back or Resolve Forward? How to Deal With Database ...
Performing a rollback requires removing all the changes of the current set that applied prior to experiencing the error.
Read more >By mistake update few data and how to rollback those ...
In order to undo changes, you'll need to start an explict transaction using BEGIN TRANSACTION, execute INSERT/UPDATE statements, and finally ...
Read more >SQL Server - Rollback Transaction Completely In Case Of Error
I recently found an issue while inserting data into a table during transactions that transaction will not completely roll back if we use ......
Read more >Rollback errors during a database upgrade - IBM
When you upgrade the OpenPages® database, the upgrade script reports the following error: [exec] Load PL/SQL package failed. Please check log file.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think we could easily add that to the graphene-sqlalchemy v3 release since it is a major release anyways. It should be a 4 liner in the codebase.
Made the changes in #353. Closing this for now. If new Issues occur, please open another Issue!