Instead of the first commit use flush.  You have already committed so
you cant roll back.

so

session.begin()
try:
    p=parent()
    session.add(p)
    session.flush()
    c=child()
    c.p_id=p.id
    session.add(c)
    session.commit()
except:
    session.rollback()


On May 20, 11:31 am, manman <[email protected]> wrote:
> session.begin()
> try:
>     p=parent()
>     session.add(p)
>     session.commit()
>     c=child()
>     c.p_id=p.id
>     session.add(c)
>     session.commit()
> except:
>     session.rollback()
>
> the example code is error, when c error, it can't rollback p. please
> tell me how to do,thanks
--~--~---------~--~----~------------~-------~--~----~
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