summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Searles-Bryant <sam@samueljsb.co.uk>2026-04-18 12:59:39 +0300
committerJacob Walls <jacobtylerwalls@gmail.com>2026-05-20 12:16:30 -0400
commit20960df455fffd73d556a5ed92cdf6832c23e65f (patch)
treeb7926cfe2c9fc3e01468d805f89a3013831df1b4
parent3ca621a38642bfd8fc2bfd308f489cc2d9e76fb0 (diff)
Fixed #37045 -- Renamed savepoint() to savepoint_create().
This makes the name consistent with the `savepoint_commit` and `savepoint_rollback` functions. The previous name is maintained as a deprecated alias. This also frees up the `savepoint` name, which would allow the context manager from `django-subatomic` to be included in Django. Co-authored-by: Lily <code@lilyf.org>
-rw-r--r--AUTHORS1
-rw-r--r--django/db/transaction.py11
-rw-r--r--docs/internals/deprecation.txt3
-rw-r--r--docs/releases/6.1.txt3
-rw-r--r--docs/topics/db/transactions.txt15
-rw-r--r--tests/transactions/tests.py11
6 files changed, 41 insertions, 3 deletions
diff --git a/AUTHORS b/AUTHORS
index 2c8d5a9845..a9403842b5 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -947,6 +947,7 @@ answer newbie questions, and generally made Django that much better:
Sachin Jat <sanch.jat@gmail.com>
Sage M. Abdullah <https://github.com/laymonage>
Sam Newman <http://www.magpiebrain.com/>
+ Sam Searles-Bryant <https://github.com/samueljsb>
Samruddhi Dharankar <sdharank@ics.uci.edu>
Sander Dijkhuis <sander.dijkhuis@gmail.com>
Sanket Saurav <sanketsaurav@gmail.com>
diff --git a/django/db/transaction.py b/django/db/transaction.py
index 1710d1ef17..269fb1c56e 100644
--- a/django/db/transaction.py
+++ b/django/db/transaction.py
@@ -1,3 +1,4 @@
+import warnings
from contextlib import ContextDecorator, contextmanager
from django.db import (
@@ -7,6 +8,7 @@ from django.db import (
ProgrammingError,
connections,
)
+from django.utils.deprecation import RemovedInDjango70Warning, django_file_prefixes
class TransactionManagementError(ProgrammingError):
@@ -46,6 +48,15 @@ def rollback(using=None):
def savepoint(using=None):
+ warnings.warn(
+ "savepoint() is deprecated. Use savepoint_create() instead.",
+ category=RemovedInDjango70Warning,
+ skip_file_prefixes=django_file_prefixes(),
+ )
+ return savepoint_create(using=using)
+
+
+def savepoint_create(using=None):
"""
Create a savepoint (if supported and required by the backend) inside the
current transaction. Return an identifier for the savepoint that will be
diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt
index 1e6415e484..2cb6a15f2f 100644
--- a/docs/internals/deprecation.txt
+++ b/docs/internals/deprecation.txt
@@ -126,6 +126,9 @@ details on these changes.
* Support for overriding ``ModelAdmin.get_action_choices()`` without the new
``action_location`` parameter will be removed.
+* The ``django.db.transaction.savepoint()`` alias to
+ ``django.db.transaction.savepoint_create()`` will be removed.
+
.. _deprecation-removed-in-6.1:
6.1
diff --git a/docs/releases/6.1.txt b/docs/releases/6.1.txt
index 12596d4fe6..b041bbdda0 100644
--- a/docs/releases/6.1.txt
+++ b/docs/releases/6.1.txt
@@ -791,6 +791,9 @@ Miscellaneous
* Overriding ``ModelAdmin.get_action_choices()`` without the new
``action_location`` parameter is deprecated.
+* ``django.db.transaction.savepoint()`` is deprecated in favor of
+ ``django.db.transaction.savepoint_create()``.
+
Features removed in 6.1
=======================
diff --git a/docs/topics/db/transactions.txt b/docs/topics/db/transactions.txt
index c44c8c6ee7..4733a95bf8 100644
--- a/docs/topics/db/transactions.txt
+++ b/docs/topics/db/transactions.txt
@@ -547,6 +547,17 @@ Savepoints are controlled by three functions in :mod:`django.db.transaction`:
.. function:: savepoint(using=None)
+ .. deprecated:: 6.1
+
+ ``savepoint`` has been renamed to ``savepoint_create``.
+
+ Creates a new savepoint. This marks a point in the transaction that is
+ known to be in a "good" state. Returns the savepoint ID (``sid``).
+
+.. function:: savepoint_create(using=None)
+
+ .. versionadded:: 6.1
+
Creates a new savepoint. This marks a point in the transaction that is
known to be in a "good" state. Returns the savepoint ID (``sid``).
@@ -579,7 +590,7 @@ The following example demonstrates the use of savepoints::
a.save()
# transaction now contains a.save()
- sid = transaction.savepoint()
+ sid = transaction.savepoint_create()
b.save()
# transaction now contains a.save() and b.save()
@@ -692,7 +703,7 @@ you can roll back the single offending operation, rather than the entire
transaction. For example::
a.save() # Succeeds, and never undone by savepoint rollback
- sid = transaction.savepoint()
+ sid = transaction.savepoint_create()
try:
b.save() # Could throw exception
transaction.savepoint_commit(sid)
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index bff1a30cf2..0baeca29e6 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -12,11 +12,13 @@ from django.db import (
transaction,
)
from django.test import (
+ SimpleTestCase,
TestCase,
TransactionTestCase,
skipIfDBFeature,
skipUnlessDBFeature,
)
+from django.utils.deprecation import RemovedInDjango70Warning
from .models import Reporter
@@ -214,7 +216,7 @@ class AtomicTests(TransactionTestCase):
def test_prevent_rollback(self):
with transaction.atomic():
reporter = Reporter.objects.create(first_name="Tintin")
- sid = transaction.savepoint()
+ sid = transaction.savepoint_create()
# trigger a database error inside an inner atomic without savepoint
with self.assertRaises(DatabaseError):
with transaction.atomic(savepoint=False):
@@ -589,3 +591,10 @@ class DurableTransactionTests(DurableTestsBase, TransactionTestCase):
class DurableTests(DurableTestsBase, TestCase):
pass
+
+
+class SavepointTests(SimpleTestCase):
+ def test_deprecation_warning(self):
+ msg = "savepoint() is deprecated. Use savepoint_create() instead."
+ with self.assertRaisesMessage(RemovedInDjango70Warning, msg):
+ transaction.savepoint()