On Apr 4, 2008, at 11:39 AM, Marcos Alcazar wrote:

>
> Hello! (Sorry about my english :) )
>
> I'm trying to resolve this by myself, but i can't. So, I hope you  
> can help me.
>
> I'm getting an IntegrityException when I try to delete an object,
> because that object is still referenced in the database.
> I want to catch that error and follow with my program normally, but I
> don't know how. It's like if the rollback is not being executed,
> because I get again the exception at the moment of the commit()
>
> My session is autoflush=True and transactional=True
>
>
> p = session.query(father).first()
> c = session.query(child).first()
> try:
>    session.delete(c)
> except:
>    session.rollback()
> p.child = 2
> session.update(p)
> session.commit()
>

I'm assuming you have some additional query statements underneath the  
session.delete() call, otherwise it wont throw an exception by itself  
like that.   The current policy with the Session is that after its  
rolled back, you have to manually clean out whatever is wrong with it  
- in this case "c" is still marked as deleted, so you'd need to  
session.update(c) to "un-delete" it (or expunge() it).  The next  
release of SQLA will have some new transactional features for sessions  
such that the "deleted" and "new" lists will be rolled back after a  
rollback(), and all in-session instances will be expired...this kind  
of thing is what we were sprinting on at Pycon.

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

Reply via email to