Skip to content

Instantly share code, notes, and snippets.

@jacobian
Created May 16, 2012 15:23
Show Gist options
  • Save jacobian/2711219 to your computer and use it in GitHub Desktop.
Save jacobian/2711219 to your computer and use it in GitHub Desktop.
@transaction.commit_manually
def foo():
db.execute("SELECT ...")
bar()
db.execute("SELECT ...")
transaction.commit()
def bar():
db.execute("INSERT ...")
### the above is exactly the same as ....
@transaction.commit_manually
def foo():
db.execute("SELECT ...")
db.execute("INSERT ...") # <--- as if bar was inlined
db.execute("SELECT ...")
transaction.commit()
### and remember that decorators aren't "magic", they just run code before a function
### so the above is also the same as ...
# <---- no decorator
def foo():
transaction.managed(True) # <---- it's a little more complex, but that's basically all commit_manually does!
db.execute("SELECT ...")
db.execute("INSERT ...") # <--- Or a call to bar() here, same thing
db.execute("SELECT ...")
transaction.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment