Skip to content

Disallow nesting part_of_a_transaction#153

Merged
meshy merged 2 commits into
mainfrom
meshy/disallow-nesting-part-of-transaction
May 1, 2026
Merged

Disallow nesting part_of_a_transaction#153
meshy merged 2 commits into
mainfrom
meshy/disallow-nesting-part-of-transaction

Conversation

@meshy
Copy link
Copy Markdown
Collaborator

@meshy meshy commented May 1, 2026

Just as it doesn't make sense for transactions to be nested, it doesn't make sense for tests to simulate nesting of parts of transactions.

This fixes #150 and is a rework of #152. In acknowledgement on the reworked commits, I have listed the commits as co-authored with @Giggitycountless.

@meshy meshy changed the title Add missing tests for part_of_a_transaction Disallow nesting part_of_a_transaction May 1, 2026
`subatomic.test.part_of_a_transaction` is part of the distributed
package, and part of the public API, so it should be tested.

Co-authored-by: Jiahao Ren <gl6532575@gmail.com>
@meshy meshy force-pushed the meshy/disallow-nesting-part-of-transaction branch from c9d1a20 to e1d62f5 Compare May 1, 2026 10:43
@meshy meshy marked this pull request as ready for review May 1, 2026 10:46
@meshy meshy requested a review from a team as a code owner May 1, 2026 10:46
Comment thread tests/test_test.py Outdated
Copy link
Copy Markdown
Collaborator

@LilyFirefly LilyFirefly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, as long as my understanding of why durable=True is appropriate in a test is accurate.

use [`transaction`][django_subatomic.db.transaction] instead.
"""
with transaction.atomic(using=using):
with transaction.atomic(using=using, durable=True):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is safe because Django has something built-in to detect and disregard the testcase transaction here too, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's right -- Django checks to see if the innermost atomic block is created by a testcase before it complains about nested durable blocks.

https://github.com/django/django/blob/9f790ef1a0f356cf6342b5d57bbaeac35aed0d9f/django/db/transaction.py#L185-L193

Add durable=True to the atomic call inside part_of_a_transaction
so that nesting is explicitly disallowed. This prevents tests from
looking like they nest partial-transaction behaviour, which does
not reflect real-world usage.

Fixes #150

Co-authored-by: Charlie Denton <charlie@meshy.co.uk>
@meshy meshy force-pushed the meshy/disallow-nesting-part-of-transaction branch from e1d62f5 to d436d0b Compare May 1, 2026 11:00
@meshy meshy merged commit 8291615 into main May 1, 2026
8 checks passed
@meshy meshy deleted the meshy/disallow-nesting-part-of-transaction branch May 1, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disallow nesting part_of_a_transaction

3 participants