﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28479	Document that transactions do not revert model state	Todor Velichkov	Jonatas CD	"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)."	Cleanup/optimization	closed	Documentation	1.11	Normal	fixed			Accepted	1	0	0	1	1	0
