On Sat, 2010-07-24 at 08:06 -0700, manman wrote:
> new_a=A()
> session.begin()
> session.add(new_a)
> session.flush()
> new_b=B()
> new_b.a_id=new_a.id
> session.add(new_b)
>
> try:
> session.commit()
> except:
> session.rollback()
> raise
>
> this code is right? when error all be rollback?
>
Should be, yes. You may verify by throwing an exception yourself:
new_a = A()
session.begin()
session.add(new_a)
session.flush()
new_b = B()
new_b.a_id = new_a.id
session.add(new_b)
try:
raise Exception("commit hasn't happened, so neither new_a nor new_b should
be persisted after the rollback")
session.commit()
except:
session.rollback()
raise
Lance
--
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.