[Django] #28479: Document that transactions do not revert model State.

8 views
Skip to first unread message

Django

unread,
Aug 8, 2017, 8:41:01 AM8/8/17
to django-...@googlegroups.com
#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.

Django

unread,
Aug 8, 2017, 10:06:32 AM8/8/17
to django-...@googlegroups.com
#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 | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


Comment:

The document to update is probably docs/topics/db/transactions.txt.

--
Ticket URL: <https://code.djangoproject.com/ticket/28479#comment:1>

Django

unread,
Aug 9, 2017, 6:05:35 AM8/9/17
to django-...@googlegroups.com
#28479: Document that transactions do not revert model state
-------------------------------------+-------------------------------------
Reporter: Todor Velichkov | Owner: Jonatas
Type: | CD
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.11

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jonatas CD):

* status: new => assigned
* owner: nobody => Jonatas CD


--
Ticket URL: <https://code.djangoproject.com/ticket/28479#comment:2>

Django

unread,
Aug 9, 2017, 6:29:56 AM8/9/17
to django-...@googlegroups.com
#28479: Document that transactions do not revert model state
-------------------------------------+-------------------------------------
Reporter: Todor Velichkov | Owner: Jonatas
Type: | CD
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.11

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
-------------------------------------+-------------------------------------
Changes (by Jonatas CD):

* has_patch: 0 => 1


Comment:

Here is the [https://github.com/django/django/pull/8873 PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/28479#comment:3>

Django

unread,
Aug 9, 2017, 6:20:44 PM8/9/17
to django-...@googlegroups.com
#28479: Document that transactions do not revert model state
-------------------------------------+-------------------------------------
Reporter: Todor Velichkov | Owner: Jonatas
Type: | CD
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.11

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/28479#comment:4>

Django

unread,
Sep 4, 2017, 3:43:47 PM9/4/17
to django-...@googlegroups.com
#28479: Document that transactions do not revert model state
-------------------------------------+-------------------------------------
Reporter: Todor Velichkov | Owner: Jonatas
Type: | CD
Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.11
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"c9b22707b0703db6c6ddaebdd00e2cd33d182e40" c9b22707]:
{{{
#!CommitTicketReference repository=""
revision="c9b22707b0703db6c6ddaebdd00e2cd33d182e40"
Fixed #28479 -- Doc'd that transaction rollback doesn't revert model
state.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28479#comment:5>

Django

unread,
Sep 4, 2017, 3:44:04 PM9/4/17
to django-...@googlegroups.com
#28479: Document that transactions do not revert model state
-------------------------------------+-------------------------------------
Reporter: Todor Velichkov | Owner: Jonatas
Type: | CD
Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.11

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"02210393097b0183ad2a462dbdfb900e450327eb" 0221039]:
{{{
#!CommitTicketReference repository=""
revision="02210393097b0183ad2a462dbdfb900e450327eb"
[1.11.x] Fixed #28479 -- Doc'd that transaction rollback doesn't revert
model state.

Backport of c9b22707b0703db6c6ddaebdd00e2cd33d182e40 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28479#comment:6>

Reply all
Reply to author
Forward
0 new messages