-
Notifications
You must be signed in to change notification settings - Fork 243
Incorrect behavior of obj.flush(): assertion failed after exception #138
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
Comments
Also, how to write code that tries to create entity, and if it fail, do nothing, but without rollback operations that was issued prior to current? nested db_session? does not work! My experiments shows sometimes It maybe SAVEPOINT, but AFAIK Pony does not support that. |
Thanks for the reporting! I'll try to fix it.
Creation of object can fail by different reasons. Some of them are valid situations, others are bugs in the application logic. I think it is not reasonable to treat all possible creation failures in the same way, because it can mask some application bugs. Typically the normal reason of failure during object creation is the violation of some unique index. I think that the most correct way is to check such indexes beforehand: username = request.args['username']
email = request.args['email']
error = None
p = Person.get(username=username)
if p is not None:
error = 'Username is already in use'
else:
p = Person.get(email=email)
if p is not None:
error = 'Email address is already in use'
else:
p = Person(username=username, email=email)
if error is not None:
... This way may be a bit verbose, but it have two benefits: (1) you can specify the most detailed error message, and (2) if creation of an object still leads to error, you will know that this error was caused by a bug in the application code.
I hope we can add SAVEPOINT support in the future, but I don't think it is a good way to solve object creation problem, because it can mask the exact reason of an error. In principle, we can change the code for creation of new object in such a way that Pony will automatically check the uniqueness of each index before execution of |
Yes, but be race-condition may occur between checking of record existence and actual inserting. |
We can add |
#54 ? |
Do not see any requirements to have only one unique column. |
|
The text was updated successfully, but these errors were encountered: