#28836 closed Cleanup/optimization (needsinfo)

Not nesting version of @atomic decorator

Reported by: Thomas Güttler Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Database transaction can't be nested.
Database transactions are ACID. And D stand for durability.

I think it is dangerous that the current implementation of @atomic falls back to savepoints, if
already inside a transaction.

I don't want to change the current default.

But I would like to have a decorator which raises an exception if the connection is already inside a transaction.

I don't care how the implementation looks like. I see two way:

  • a new method. For example @non_nesting_atomic
  • a kwarg: For example @atomic(non_nesting=True) with a default of "False" for backward compatibility.

What do you think?

Change History (2)

comment:1 Changed 11 months ago by Aymeric Augustin

The name @atomic was chosen to focus on A (atomicity).

The current way to check if you're in a transaction is the following:

if not transaction.get_autocommit():
    raise Exception("already in a transaction")

with transaction.atomic():

... which is less than intuitive, sorry.

I don't have a clear opinion on the suggestion you're making.

comment:2 Changed 11 months ago by Tim Graham

Component: UncategorizedDatabase layer (models, ORM)
Resolution: needsinfo
Status: newclosed
Type: UncategorizedCleanup/optimization
Note: See TracTickets for help on using tickets.
Back to Top