From 20960df455fffd73d556a5ed92cdf6832c23e65f Mon Sep 17 00:00:00 2001 From: Samuel Searles-Bryant Date: Sat, 18 Apr 2026 12:59:39 +0300 Subject: 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 --- AUTHORS | 1 + django/db/transaction.py | 11 +++++++++++ docs/internals/deprecation.txt | 3 +++ docs/releases/6.1.txt | 3 +++ docs/topics/db/transactions.txt | 15 +++++++++++++-- tests/transactions/tests.py | 11 ++++++++++- 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 Sage M. Abdullah Sam Newman + Sam Searles-Bryant Samruddhi Dharankar Sander Dijkhuis Sanket Saurav 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() -- cgit v1.3