You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/transactions-savepoints-and-atomic.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,14 +16,14 @@ and is committed with `COMMIT`.
16
16
A transaction can be ended without committing using `ROLLBACK`.
17
17
18
18
When using Django Subatomic,
19
-
transactions are created with `django_subatomic.db.transaction`,
19
+
transactions are created with [`transaction`][django_subatomic.db.transaction],
20
20
which can be used as both a decorator and a context manager.
21
21
22
22
!!! Note
23
23
24
24
SQL does not support nested transactions,
25
25
so nesting is not supported by `transaction`.
26
-
It acts like [Django's `atomic` with `durable=True`](https://docs.djangoproject.com/en/5.0/topics/db/transactions/#controlling-transactions-explicitly).
26
+
It acts like [Django's `atomic` with `durable=True`][django-atomic]
27
27
28
28
See [_Atomic code_](#atomic-code)
29
29
for code which requires a transaction, but doesn't require partial rollback.
@@ -51,7 +51,7 @@ In SQL terms, a savepoint is created with `SAVEPOINT <name>`.
51
51
It is rolled back with `ROLLBACK TO <name>`
52
52
and discarded with `RELEASE SAVEPOINT <name>`.
53
53
54
-
Subatomic creates savepoints using `django_subatomic.db.savepoint`.
54
+
Subatomic creates savepoints using [`savepoint`][django_subatomic.db.savepoint].
55
55
This is a context manager,
56
56
and cannot be used as a decorator.
57
57
@@ -65,23 +65,23 @@ and cannot be used as a decorator.
65
65
Sometimes code needs to make multiple database changes atomically
66
66
in a place that should not be responsible for managing a transactions.
67
67
68
-
Decorate this code with `@django_subatomic.db.transaction_required`
68
+
Decorate this code with [`@transaction_required`][django_subatomic.db.transaction_required]
69
69
to make it raise an exception when someone tries to run it without first opening a transaction.
70
70
71
71
!!! Tip
72
72
73
-
Where possible, use `transaction_required` as a decorator.
73
+
Where possible, use [`transaction_required`][django_subatomic.db.transaction_required] as a decorator.
74
74
75
75
This form is preferred because it fails earlier,
76
76
and presents a clearer requirement to programmers.
77
77
78
-
You can still use `transaction_required` as a context manager though.
78
+
You can still use [`transaction_required`][django_subatomic.db.transaction_required] as a context manager though.
79
79
This might be useful in code where you cannot know the required database
80
80
(such as when the database name is passed in as a function parameter).
81
81
82
82
!!! Warning
83
83
84
-
When testing code which uses `transaction_required`
84
+
When testing code which uses [`transaction_required`][django_subatomic.db.transaction_required],
85
85
you might see `_MissingRequiredTransaction`
86
86
even though tests are run in a transaction by default.
87
87
@@ -93,15 +93,15 @@ to make it raise an exception when someone tries to run it without first opening
93
93
then you have probably forgotten to open a transaction.
94
94
95
95
The trade-off is that lower-level tests will see this error too.
96
-
If you're testing `transaction_required` code directly,
96
+
If you're testing [`transaction_required`][django_subatomic.db.transaction_required] code directly,
97
97
and you're _sure_ that the code shouldn't be responsible for opening a transaction,
98
-
use the `django_subatomic.test.part_of_a_transaction()` decorator/context-manager
98
+
use the [`part_of_a_transaction`][django_subatomic.test.part_of_a_transaction] decorator/context-manager
99
99
to get things working.
100
100
This will not run after-commit hooks.
101
101
If you'd like those to run, create a [transaction](#transactions) instead.
102
102
103
103
When "create-a-transaction-if-one-doesn't-already-exist" behaviour is required,
104
-
the `transaction_if_not_already` function will provide it.
104
+
the [`transaction_if_not_already`][django_subatomic.db.transaction_if_not_already] function will provide it.
105
105
This approach hints that transactional behaviour is not well-defined:
106
106
the code will do different things in different contexts,
107
107
which makes it hard to know what to expect from it.
0 commit comments