#28479 closed Cleanup/optimization (fixed)
Document that transactions do not revert model state
Reported by: | Todor Velichkov | Owned by: | Jonatas CD |
---|---|---|---|
Component: | Documentation | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | yes | UI/UX: | no |
Description
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).
Change History (6)
comment:1 Changed 4 years ago by
Summary: | Document that transactions do not revert model State. → Document that transactions do not revert model state |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 Changed 4 years ago by
Owner: | changed from nobody to Jonatas CD |
---|---|
Status: | new → assigned |
comment:4 Changed 4 years ago by
Patch needs improvement: | set |
---|
Note: See
TracTickets for help on using
tickets.
The document to update is probably docs/topics/db/transactions.txt.