Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Incorrect behavior of obj.flush(): assertion failed after exception #138
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