On Wed, Oct 28, 2009 at 12:29 PM, Zhang Huangbin <[email protected]> wrote:
>
> It seems there's a error in cookbook article:
> http://webpy.org/cookbook/sqlalchemy
>
> Original code snippet:
> ----
> def load_sqla(handler):
> web.ctx.orm = scoped_session(sessionmaker(bind=engine))
> try:
> return handler()
> except web.HTTPError:
> web.ctx.orm.commit()
> raise
> except:
> web.ctx.orm.rollback()
> raise
> finally:
> web.ctx.orm.commit()
> ----
>
> It should be:
> ----
> def load_sqla(handler):
> web.ctx.orm = scoped_session(sessionmaker(bind=engine))
> try:
> try:
> return handler()
> except web.HTTPError:
> web.ctx.orm.commit()
> raise
> except:
> web.ctx.orm.rollback()
> raise
> finally:
> web.ctx.orm.commit()
It will execute commit twice or rollback + commit.
The correct code should probably be this:
def load_sqla(handler):
web.ctx.orm = scoped_session(sessionmaker(bind=engine))
try:
return handler()
except web.HTTPError:
web.ctx.orm.commit()
raise
except:
web.ctx.orm.rollback()
raise
else:
web.ctx.orm.commit()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" 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/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---