Skip to content

Commit 65258b3

Browse files
committed
docs
1 parent 57c3683 commit 65258b3

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

django_mongodb_backend/features.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class DatabaseFeatures(BaseDatabaseFeatures):
9797
"expressions.tests.ExpressionOperatorTests.test_lefthand_transformed_field_bitwise_or",
9898
}
9999
_django_test_expected_failures_transactions = {
100-
# When get_or_create() fails with IntegrityError, the transaction is no longer usable.
100+
# When update_or_create() fails with IntegrityError, the transaction
101+
# is no longer usable.
101102
"get_or_create.tests.UpdateOrCreateTests.test_manual_primary_key_test",
102103
"get_or_create.tests.UpdateOrCreateTestsWithManualPKs.test_create_with_duplicate_primary_key",
103104
}

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"pymongo": ("https://pymongo.readthedocs.io/en/stable/", None),
4646
"python": ("https://docs.python.org/3/", None),
4747
"atlas": ("https://www.mongodb.com/docs/atlas/", None),
48+
"manual": ("https://www.mongodb.com/docs/manual/", None),
4849
}
4950

5051
root_doc = "contents"

docs/source/ref/database.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,45 @@ effect. Rather, if you need to close the connection pool, use
4141
.. versionadded:: 5.2.0b0
4242

4343
Support for connection pooling and ``connection.close_pool()`` were added.
44+
45+
.. _transactions:
46+
47+
Transactions
48+
============
49+
50+
.. versionadded:: 5.2.0b2
51+
52+
Support for :doc:`Django's transactions APIs <django:topics/db/transactions>`
53+
is enabled if the MongoDB configuration supports them: MongoDB must be
54+
configured as a :doc:`replica set <manual:replication>` or :doc:`sharded
55+
cluster <manual:sharding>`, and the store engine must be :doc:`WiredTiger
56+
<manual:core/wiredtiger>`.
57+
58+
If transactions aren't supported, query execution uses Django and MongoDB's
59+
default behavior of autocommit mode. Each query is immediately committed to the
60+
database. Django's transaction management APIs, such as
61+
:func:`~django.db.transaction.atomic`, function as no-ops.
62+
63+
.. _transactions-limitations:
64+
65+
Limitations
66+
-----------
67+
68+
MongoDB's transaction limitations that are applicable to Django are:
69+
70+
- :meth:`QuerySet.union() <django.db.models.query.QuerySet.union>` is not
71+
supported inside a transaction.
72+
- If a transaction raises an exception, the transaction is no longer usable.
73+
For example, if the update stage of :meth:`QuerySet.update_or_create()
74+
<django.db.models.query.QuerySet.update_or_create>` fails with
75+
:class:`~django.db.IntegrityError` due to a unique constraint violation, the
76+
create stage won't be able to proceed.
77+
:class:`pymongo.errors.OperationFailure` is raised, wrapped by
78+
:class:`django.db.DatabaseError`.
79+
- Savepoints (i.e. nested :func:`~django.db.transaction.atomic` blocks) aren't
80+
supported. The outermost :func:`~django.db.transaction.atomic` will start
81+
a transaction while any subsequent :func:`~django.db.transaction.atomic`
82+
blocks will have no effect.
83+
- Migration operations aren't :ref:`wrapped in a transaction
84+
<topics/migrations:transactions>` because of MongoDB restrictions such as
85+
adding indexes to existing collections while in a transaction.

docs/source/releases/5.2.x.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
Django MongoDB Backend 5.2.x
33
============================
44

5+
5.2.0 beta 2
6+
============
7+
8+
*Unreleased*
9+
10+
New features
11+
------------
12+
13+
- Added support for :ref:`database transactions <transactions>`.
14+
515
5.2.0 beta 1
616
============
717

docs/source/topics/known-issues.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ Database functions
8080
Transaction management
8181
======================
8282

83-
Query execution uses Django and MongoDB's default behavior of autocommit mode.
84-
Each query is immediately committed to the database.
85-
86-
Django's :doc:`transaction management APIs <django:topics/db/transactions>`
87-
are not supported.
83+
See :ref:`transactions` for details.
8884

8985
Database introspection
9086
======================

0 commit comments

Comments
 (0)