Is it possible to repeat the code within a
with
statement?
No.
As pointed out earlier in that mailing list thread, you can reduce a bit of duplication by making the decorator call the passed function:
def do_work():
...
# This is not ideal!
@transaction(retries=3)
def _perform_in_transaction():
# Atomic DB statements
...
# called implicitly
...