On Dec 14, 2008, at 12:07 PM, Hinrich Winther wrote:

>
>>> I am using SQLAlchemy 0.5rc4.
>>> Is there a way to test if the values of an object are valid
>>> for
>>> commiting? I tried something like:
>>> try:
>>>     session.commit()
>>> except:
>>>     notify the user
>>>
>>> But the problem is, that if the commit fails and I change the non
>>> valid value to a valid one the session will still not commit.
>> why? if u try again and all is ok...
>
> If I try again with valid values (in my case I first entered a too
> long string for a varchar(50) and then corrected it) I get a
> sqlalchemy.exc.InvalidRequestError with the info:
> "The transaction is inactive due to a rollback in a subtransaction.
> Issue rollback() to cancel the transaction."
> If I issue the rollback I can commit the session but all the previos
> entered data is lost. It would be more friendly to try to commit the
> session and if it fails to let the user change the values and try  
> again.

the session cannot issue partially complete flushes - when a flush  
fails, all the SQL that the flush has issued needs to be rolled  
back.   In addition, many databases like Postgres have this  
requirement in any case (ROLLBACK is required after an integrity  
violation) so SQLA could never remove this restriction completely.

If you'd like to try flushing data, catch an exception, and then try  
again, use a SAVEPOINT which is available via begin_nested().   Its  
better not to rely upon exceptions to check for constraint compliance.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to