#28479: Document that transactions do not revert model State.
------------------------------------------------+------------------------
               Reporter:  Todor Velichkov       |          Owner:  nobody
                   Type:  Cleanup/optimization  |         Status:  new
              Component:  Documentation         |        Version:  1.11
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  1
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 I know this may be obvious, but I think its worth mentioning in the
 documentation that when a transaction rollback happen your model/s state
 will not be reverted, thus the underlying model instance/s may end up in
 an inconsistent state if not manually reverted.

 A simple toy example:

 {{{
 from django.db import IntegrityError, transaction
 from django.contrib.auth.models import User

 def update_user(pk, username):
     user = User.objects.get(pk=pk)
     try:
         with transaction.atomic():
             user.username = username
             user.is_active = False
             user.save()
             return user
     except IntegrityError:
         return user
 }}}

 since `username` is an unique field if an IntegrityError happen and the
 transaction got reverted, the user which we return will have an
 inconsistent state (if not manually reverted).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28479>
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 
https://groups.google.com/d/msgid/django-updates/057.cc1d3358cd1d86e7c659f15c3343832f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to