-
Notifications
You must be signed in to change notification settings - Fork 6
add explanation for the problem with atomic #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
meshy
merged 3 commits into
kraken-tech:main
from
Amy-Franz:add-explination-for-the-problem
Sep 23, 2025
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| ## Django's Atomic | ||||||||||||||||||||||||||||||||||||||||||||
| Django's `atomic` ensures database changes are committed together-or-not-at-all. It creates a savepoint or a transaction depending on two factors: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| - The arguments passed to it (`durable` and `savepoint`). | ||||||||||||||||||||||||||||||||||||||||||||
| - If a database transaction is already open. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Specifically, the **Behaviours** which `atomic` exhibits are: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| | | `durable=False` (default) | `durable=True` | | ||||||||||||||||||||||||||||||||||||||||||||
| | --- | --- | --- | | ||||||||||||||||||||||||||||||||||||||||||||
| | `savepoint=True` (default) | **A**. Begin a transaction if needed. Creates a savepoint if already in a transaction. | **B**. Begin a transaction, or throw an error if one is already open. Never creates a savepoint. (The `savepoint` flag is ignored.) | | ||||||||||||||||||||||||||||||||||||||||||||
| | `savepoint=False` | **C**. Begin a transaction if needed. Never creates a savepoint. | **D**. Same as **B**. | | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Uses of `atomic` fall into three broad **Categories**: | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| 1. Create a *transaction* to wrap multiple changes. | ||||||||||||||||||||||||||||||||||||||||||||
| 2. Create a *savepoint* so we can roll back to in order to continue with a transaction after failure. | ||||||||||||||||||||||||||||||||||||||||||||
| 3. Changes to be committed *atomically*, but not specific about where the transaction is created, as long as there is one. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ## Problems | ||||||||||||||||||||||||||||||||||||||||||||
| 1. Django's atomic creates many savepoints that are never used. There are a couple of main causes: | ||||||||||||||||||||||||||||||||||||||||||||
| 1. We create savepoints with decorators. *Linting for this is possible, but each existing case requires investigation.* | ||||||||||||||||||||||||||||||||||||||||||||
| 2. `atomic` creates savepoints by default. The default arguments (*Behaviour* **A**) are an [attractive nuisance](https://blog.ganssle.io/articles/2023/01/attractive-nuisances.html) because they make us create savepoints when we don't need them. | ||||||||||||||||||||||||||||||||||||||||||||
| > … if you have two ways to accomplish a task and one is a simple way that *looks* like the right thing but is subtly wrong, and the other is correct but | ||||||||||||||||||||||||||||||||||||||||||||
| more complicated, the majority of people will end up doing the wrong | ||||||||||||||||||||||||||||||||||||||||||||
| thing. | ||||||||||||||||||||||||||||||||||||||||||||
| — [**Attractive nuisances in software design](https://blog.ganssle.io/articles/2023/01/attractive-nuisances.html) -** [Paul Ganssle](https://blog.ganssle.io/author/paul-ganssle.html) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| — [**Attractive nuisances in software design](https://blog.ganssle.io/articles/2023/01/attractive-nuisances.html) -** [Paul Ganssle](https://blog.ganssle.io/author/paul-ganssle.html) | |
| — [**Attractive nuisances in software design**](https://blog.ganssle.io/articles/2023/01/attractive-nuisances.html) - [Paul Ganssle](https://blog.ganssle.io/author/paul-ganssle.html) |
Comment on lines
+20
to
+30
Collaborator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has got a bit mixed up in formatting.
Suggested change
| ## Problems | |
| 1. Django's atomic creates many savepoints that are never used. There are a couple of main causes: | |
| 1. We create savepoints with decorators. *Linting for this is possible, but each existing case requires investigation.* | |
| 2. `atomic` creates savepoints by default. The default arguments (*Behaviour* **A**) are an [attractive nuisance](https://blog.ganssle.io/articles/2023/01/attractive-nuisances.html) because they make us create savepoints when we don't need them. | |
| > … if you have two ways to accomplish a task and one is a simple way that *looks* like the right thing but is subtly wrong, and the other is correct but | |
| more complicated, the majority of people will end up doing the wrong | |
| thing. | |
| — [**Attractive nuisances in software design](https://blog.ganssle.io/articles/2023/01/attractive-nuisances.html) -** [Paul Ganssle](https://blog.ganssle.io/author/paul-ganssle.html) | |
| > | |
| 3. We have no easy way to indicate the creation of a savepoint that doesn't have the potential to create a transaction instead. The only tool we have to create a savepoint is *Behaviour* **A**, which can create a transaction. | |
| ## Problems | |
| Django's atomic creates many savepoints that are never used. There are a couple of main causes: | |
| 1. We create savepoints with decorators. *Linting for this is possible, but each existing case requires investigation.* | |
| 2. `atomic` creates savepoints by default. The default arguments (*Behaviour* **A**) are an [attractive nuisance](https://blog.ganssle.io/articles/2023/01/attractive-nuisances.html) because they make us create savepoints when we don't need them. | |
| > … if you have two ways to accomplish a task and one is a simple way that *looks* like the right thing but is subtly wrong, and the other is correct but | |
| more complicated, the majority of people will end up doing the wrong | |
| thing. | |
| — [**Attractive nuisances in software design](https://blog.ganssle.io/articles/2023/01/attractive-nuisances.html) -** [Paul Ganssle](https://blog.ganssle.io/author/paul-ganssle.html) | |
| > | |
| 3. We have no easy way to indicate the creation of a savepoint that doesn't have the potential to create a transaction instead. The only tool we have to create a savepoint is *Behaviour* **A**, which can create a transaction. |
meshy marked this conversation as resolved.
Show resolved
Hide resolved
meshy marked this conversation as resolved.
Show resolved
Hide resolved
meshy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
meshy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
meshy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
meshy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,5 +9,7 @@ extra: | |
| alias: true | ||
| default: | ||
| - latest | ||
| markdown_extensions: | ||
| - tables | ||
| plugins: | ||
| - mike | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds a little internal, so perhaps should be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think we can just simplify this:
That point probably requires a bit of explanation, but we can add that when we revise this.