On Jan 22, 2012, at 8:21 PM, Jackson, Cameron wrote:

> So I figured out that I can do this:
>     try:
>         self.session.delete(row)
>         self.session.flush()
> except sqlalchemy.exc.IntegrityError:
>         print "Can't do that!"
>  
> But that really isn't a lot of help, because I'm now stuck with a useless 
> transaction. If the user makes a bunch of changes, then tries to delete 
> something that's still being referenced elsewhere, I have to rollback() 
> *everything* they've done so far. Not good.
>  
> So I either need a way to rollback *just* the dodgy deletion, or a way to 
> anticipate the IntegrityError and not do the deletion at all. The latter 
> would be better, but I'm OK with either..

how would you guard against a "useless transaction" assuming normal ORM usage 
with queries and all of that in any case ?      the transaction starts as soon 
as they look at the database in any way.

anyway, there's no way to know if the DB has rows that point to a target row 
without querying the database at some point, so not sure what you want to do 
there.


-- 
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