-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incompleted transactions with PostgreSQL #240
Comments
Sorry, I missed a couple of updates :( After updating works great! 👍 |
No, bug is still present in 2.1.4 and in current development version with Python 3.3 at least. (Last time I just reproduced it incorrectly). |
You will need to issue a User.create(username='test')
try:
User.create(username='test') # error
except:
db.rollback()
# Continue as normal. |
Sure, that's workaround. It seems that I should wrap every save / update / create into |
Well, I think it's developer's responsibility to handle application level errors e.g.: try:
User.create(username='test') # error
except User.ValidationError:
pass # do something And I think database level errors should be handled under the hood in 'autopilot' mode - which is 'autocommit' mode. Does that sound reasonable? :) |
I think I can write an implementation and I'd want to work out good design solution :) Another smaller problem I faced with explicit rollback is that I have to import global database User.create(username='test')
try:
User.create(username='test') # error
except:
db.rollback() I think |
In my opinion it is not a workaround -- if you do not handle transactions or application errors properly peewee won't try to figure out how to fix it for you. There are a number of transaction helpers that can help you avoid the "wrap every query" part: |
Ok, I see the point. My suggestion is consider |
Right, and that's how it works, but if you trigger an Closing this as it is expected behavior. |
Ok, then :) May be this should be highlighted somewhere is docs. I didn't actually expect that common single wrong |
Just want to chime in that this is unexpected to me as well. @coleifer, in response to
you say,
But the whole idea of a having to rollback an "implied transaction" seems at odds with the stated notion of "I don't want to know about transactions." I don't see a circumstance where code with |
My expectation of what is "reasonable" behavior for these connections is I agree, it is weird to roll back a transaction you never opened because On Fri, Jan 10, 2014 at 7:07 PM, Tim Conkling notifications@github.comwrote:
|
As a new user of peewee (which is great - thanks for creating & maintaining it!), I'm very much in favor of changing the default; the current behavior was confusing to me when I switched my underlying database from sqlite to postgres and started getting errors about open transactions that had not existed with sqlite. Of course, I don't have tons of code to maintain that uses peewee that would be negatively affected by this change. Regardless, I'd argue that - semantically speaking - |
Added fbd6c20 which adds a new parameter to the db = PostgresqlDatabase('my_db', autocommit=True, autorollback=True) |
I was hit by this issue too. The default value for Nevertheless I assumed a rollback would be issued in case of any exception, but apparently I was wrong... |
What do you mean it's wrong? It's documented as being |
Yes, it is. But as pointed out in previous comments most people rely on deafults and this is not the expected behavior in most cases. |
@romanek-adam But it is documented and backward compatible! It's generally not a good idea to change defaults one day. Probably it would be good to add some notes on |
How to deal with incompleted transactions in PostgreSQL? It seems we can't make queries after single transaction fail. Instead we get: psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block
Here's minimal code sample to reproduce the issue:
So, I get single user with username "test". If I try to create another one, I'll get an error:
And that's predictable and fine! (By the way, how should we catch this kind of exception?)
But when I try to make another request, it fails:
And I need to drop database connection and create a new one to make it work again.
The text was updated successfully, but these errors were encountered: