I got a lot of errors with the message :
"DatabaseError: current transaction is aborted, commands ignored until end of transaction block"
after changed from python-psycopg to python-psycopg2 as Django project's database engine.
The code remains the same, just dont know where those errors are from.
In my experience, these errors happen this way:
There nothing wrong with the second query, but since the real error was caught, the second query is the one that raises the (much less informative) error.
edit: this only happens if the
except
clause catchesIntegrityError
(or any other low level database exception), If you catch something likeDoesNotExist
this error will not come up, becauseDoesNotExist
does not corrupt the transaction.The lesson here is don't do try/except/pass.
I just had this error too but it was masking another more relevant error message where the code was trying to store a 125 characters string in a 100 characters column:
I had to debug through the code for the above message to show up, otherwise it displays
This is very strange behavior for me. I'm surprised that no one thought of savepoints. In my code failing query was expected behavior:
I have changed code this way to use savepoints:
In response to @priestc and @Sebastian, what if you do something like this?
I just tried this code and it seems to work, failing silently without having to care about any possible errors, and working when the query is good.