Skip to content

Commit 1bbb907

Browse files
committed
remove durable
1 parent 08b101a commit 1bbb907

File tree

3 files changed

+5
-61
lines changed

3 files changed

+5
-61
lines changed

django_mongodb_backend/transaction.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,13 @@ class Atomic(ContextDecorator):
3030
`with oa:` multiple times.
3131
3232
Since database connections are thread-local, this is thread-safe.
33-
34-
An atomic block can be tagged as durable. In this case, a RuntimeError is
35-
raised if it's nested within another atomic block. This guarantees
36-
that database changes in a durable block are committed to the database when
37-
the block exits without error.
3833
"""
3934

40-
def __init__(self, using, durable):
35+
def __init__(self, using):
4136
self.using = using
42-
self.durable = durable
4337

4438
def __enter__(self):
4539
connection = get_connection(self.using)
46-
47-
if self.durable and connection.atomic_blocks_mongo:
48-
raise RuntimeError(
49-
"A durable atomic block cannot be nested within another atomic block."
50-
)
5140
if not connection.in_atomic_block_mongo:
5241
# Reset state when entering an outermost atomic block.
5342
connection.commit_on_exit_mongo = True
@@ -123,10 +112,10 @@ def __exit__(self, exc_type, exc_value, traceback):
123112
connection.in_atomic_block_mongo = False
124113

125114

126-
def atomic(using=None, durable=False):
115+
def atomic(using=None):
127116
# Bare decorator: @atomic -- although the first argument is called
128117
# `using`, it's actually the function being decorated.
129118
if callable(using):
130-
return Atomic(DEFAULT_DB_ALIAS, durable)(using)
119+
return Atomic(DEFAULT_DB_ALIAS)(using)
131120
# Decorator: @atomic(...) or context manager: with atomic(...): ...
132-
return Atomic(using, durable)
121+
return Atomic(using)

docs/source/topics/transactions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ autocommit mode. Each query is immediately committed to the database.
2323
Controlling transactions
2424
========================
2525

26-
.. function:: atomic(using=None, durable=False)
26+
.. function:: atomic(using=None)
2727

2828
Atomicity is the defining property of database transactions. ``atomic`` allows
2929
creating a block of code within which the atomicity on the database is guaranteed.

tests/transactions_/tests.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -160,48 +160,3 @@ def __call__(self):
160160

161161
# Must not raise an exception
162162
transaction.atomic(Callable())
163-
164-
165-
class DurableTests(TransactionTestCase):
166-
available_apps = ["transactions_"]
167-
168-
def test_commit(self):
169-
with transaction.atomic(durable=True):
170-
reporter = Reporter.objects.create(first_name="Tintin")
171-
self.assertEqual(Reporter.objects.get(), reporter)
172-
173-
def test_nested_outer_durable(self):
174-
with transaction.atomic(durable=True):
175-
reporter1 = Reporter.objects.create(first_name="Tintin")
176-
with transaction.atomic():
177-
reporter2 = Reporter.objects.create(
178-
first_name="Archibald",
179-
last_name="Haddock",
180-
)
181-
self.assertSequenceEqual(Reporter.objects.all(), [reporter2, reporter1])
182-
183-
def test_nested_both_durable(self):
184-
msg = "A durable atomic block cannot be nested within another atomic block."
185-
with (
186-
transaction.atomic(durable=True),
187-
self.assertRaisesMessage(RuntimeError, msg),
188-
transaction.atomic(durable=True),
189-
):
190-
pass
191-
192-
def test_nested_inner_durable(self):
193-
msg = "A durable atomic block cannot be nested within another atomic block."
194-
with (
195-
transaction.atomic(),
196-
self.assertRaisesMessage(RuntimeError, msg),
197-
transaction.atomic(durable=True),
198-
):
199-
pass
200-
201-
def test_sequence_of_durables(self):
202-
with transaction.atomic(durable=True):
203-
reporter = Reporter.objects.create(first_name="Tintin 1")
204-
self.assertEqual(Reporter.objects.get(first_name="Tintin 1"), reporter)
205-
with transaction.atomic(durable=True):
206-
reporter = Reporter.objects.create(first_name="Tintin 2")
207-
self.assertEqual(Reporter.objects.get(first_name="Tintin 2"), reporter)

0 commit comments

Comments
 (0)