#30005: Example in documentation of transaction.atomic uses both decorator and
context manager
     Reporter:  Peter Hull     |                    Owner:  Peter Hull
         Type:  Bug            |                   Status:  assigned
    Component:  Documentation  |                  Version:  2.1
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  1              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  1              |                    UI/UX:  0

Comment (by Simon Charette):

 I don't think the example is wrong at all as the inner
 `transaction.atomic` block creates a `SAVEPOINT` (because
 `atomic(savepoint)` defaults to `True`) and thus the connection is usable
 in the event of an `IntegrityError` because a rollback of the savepoint
 would happen.

 What the example is trying to demonstrate is that you can still nest
 `transaction.atomic()` block safely if you wrap code expected to raise
 database error appropriately and have queries within it's context be
 atomic. In this case the `create_parent()` and `add_children()` calls will
 be executed in the same transaction because of the function decorator.

 Think of it this way, `atomic` would be completely impossible to use if
 you couldn't nest calls this way given each calls to the database can
 theoretically raise a database exception.

Ticket URL: <https://code.djangoproject.com/ticket/30005#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to