Skip to content

Commit 03a7b5b

Browse files
committed
Link to our API docs when we discuss our API
1 parent 82f0f1f commit 03a7b5b

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

docs/transactions-savepoints-and-atomic.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and is committed with `COMMIT`.
1616
A transaction can be ended without committing using `ROLLBACK`.
1717

1818
When using Django Subatomic,
19-
transactions are created with `django_subatomic.db.transaction`,
19+
transactions are created with [`transaction`][django_subatomic.db.transaction],
2020
which can be used as both a decorator and a context manager.
2121

2222
!!! Note
@@ -51,7 +51,7 @@ In SQL terms, a savepoint is created with `SAVEPOINT <name>`.
5151
It is rolled back with `ROLLBACK TO <name>`
5252
and discarded with `RELEASE SAVEPOINT <name>`.
5353

54-
Subatomic creates savepoints using `django_subatomic.db.savepoint`.
54+
Subatomic creates savepoints using [`savepoint`][django_subatomic.db.savepoint].
5555
This is a context manager,
5656
and cannot be used as a decorator.
5757

@@ -65,23 +65,23 @@ and cannot be used as a decorator.
6565
Sometimes code needs to make multiple database changes atomically
6666
in a place that should not be responsible for managing a transactions.
6767

68-
Decorate this code with `@django_subatomic.db.transaction_required`
68+
Decorate this code with [`@transaction_required`][django_subatomic.db.transaction_required]
6969
to make it raise an exception when someone tries to run it without first opening a transaction.
7070

7171
!!! Tip
7272

73-
Where possible, use `transaction_required` as a decorator.
73+
Where possible, use [`transaction_required`][django_subatomic.db.transaction_required] as a decorator.
7474

7575
This form is preferred because it fails earlier,
7676
and presents a clearer requirement to programmers.
7777

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.
7979
This might be useful in code where you cannot know the required database
8080
(such as when the database name is passed in as a function parameter).
8181

8282
!!! Warning
8383

84-
When testing code which uses `transaction_required`
84+
When testing code which uses [`transaction_required`][django_subatomic.db.transaction_required],
8585
you might see `_MissingRequiredTransaction`
8686
even though tests are run in a transaction by default.
8787

@@ -93,15 +93,15 @@ to make it raise an exception when someone tries to run it without first opening
9393
then you have probably forgotten to open a transaction.
9494

9595
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,
9797
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
9999
to get things working.
100100
This will not run after-commit hooks.
101101
If you'd like those to run, create a [transaction](#transactions) instead.
102102

103103
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.
105105
This approach hints that transactional behaviour is not well-defined:
106106
the code will do different things in different contexts,
107107
which makes it hard to know what to expect from it.

docs/why.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ developers must know that it will do different database operations
4747
depending on who calls it.
4848

4949
Subatomic avoids this issue
50-
by offering an unambiguous API (`transaction()`, `savepoint()`, etc).
50+
by offering an unambiguous API
51+
([`transaction()`][django_subatomic.db.transaction], [`savepoint()`][django_subatomic.db.savepoint], etc).
5152

5253
### Transactions without context
5354

@@ -75,7 +76,7 @@ the creation of a savepoint (*Outcome* **2**)
7576
or the need for atomicity (*Outcome* **3**)
7677
that doesn't have the potential to create a transaction instead.
7778

78-
A function decorated with Subatomic's `@transaction_required`
79+
A function decorated with Subatomic's [`@transaction_required`][django_subatomic.db.transaction_required]
7980
will raise an error when called outside of a transaction,
8081
rather than run the risk of creating a transaction with the wrong scope.
8182

@@ -90,7 +91,7 @@ to indicate that code should be atomic (*Outcome* **3**),
9091
but neglect to pass `savepoint=False`.
9192
This results in more database queries than necessary.
9293

93-
Subatomic's `@transaction_required` decorator
94+
Subatomic's [`@transaction_required`][django_subatomic.db.transaction_required] decorator
9495
gives developers an unambiguous alternative
9596
that will never open a savepoint.
9697

@@ -115,7 +116,7 @@ because [`atomic`][atomic]'s API is ambiguous,
115116
it can be hard to know the intended *Outcome*.
116117

117118
To encourage putting rollback logic alongside savepoint creation,
118-
Subatomic's `savepoint` cannot be used as a decorator.
119+
Subatomic's [`savepoint`][django_subatomic.db.savepoint] cannot be used as a decorator.
119120

120121
### Tests without after-commit callbacks
121122

@@ -141,7 +142,7 @@ which is prone to error and omission,
141142
or run the test using [`TransactionTestCase`][TransactionTestCase],
142143
which can be very slow.
143144

144-
Subatomic's `transaction()` function
145+
Subatomic's [`transaction()`][django_subatomic.db.transaction] function
145146
will run after-commit callbacks automatically in tests
146147
so that code behaves the same in tests as it does in production.
147148

0 commit comments

Comments
 (0)