I love assert

Tim Chase python.list at tim.thechases.com
Fri Nov 14 21:14:53 EST 2014


On 2014-11-15 12:48, Chris Angelico wrote:
> conn = establish_database_connection()
> try:
>     do_stuff()
> finally:
>     conn.rollback()

this sounds suspiciously like you'd never actually commit.  Do you
mean something like

  conn = establisth_database_connection()
  try:
    do_stuff(conn)
  except:
    conn.rollback()
    raise

instead?

I don't generally like bare excepts, but in this case, the exception
just gets re-raised, so I feel Less Bad™ about it (there's still the
case where the rollback call raises some alternate exception,
obfuscating the underlying root issue).

-tkc






More information about the Python-list mailing list