question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I roll back after a database error?

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
erikwredecommented, Apr 28, 2022

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.

0reactions
erikwredecommented, Jun 9, 2022

Made the changes in #353. Closing this for now. If new Issues occur, please open another Issue!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found