From 350e447cb747fd01e26fe6a05a4b8c6edbca51a4 Mon Sep 17 00:00:00 2001 From: "utkarsh.arya@zomato.com" Date: Sat, 15 Nov 2025 22:56:40 +0000 Subject: [PATCH] Simplify execute_sql_flush() signature to drop 'using' Now infers database alias from self.connection. Reduces redundancy and clarifies API usage. --- django/core/management/commands/flush.py | 2 +- django/db/backends/base/operations.py | 4 ++-- tests/backends/base/test_operations.py | 2 +- tests/backends/tests.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py index e8ed3967f7..bc8021cf4e 100644 --- a/django/core/management/commands/flush.py +++ b/django/core/management/commands/flush.py @@ -60,7 +60,7 @@ Are you sure you want to do this? if confirm == 'yes': try: - connection.ops.execute_sql_flush(database, sql_list) + connection.ops.execute_sql_flush(sql_list) except Exception as exc: raise CommandError( "Database %s couldn't be flushed. Possible reasons:\n" diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index 70ac07ae09..f07580c18b 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -400,9 +400,9 @@ class BaseDatabaseOperations: """ raise NotImplementedError('subclasses of BaseDatabaseOperations must provide a sql_flush() method') - def execute_sql_flush(self, using, sql_list): + def execute_sql_flush(self, sql_list): """Execute a list of SQL statements to flush the database.""" - with transaction.atomic(using=using, savepoint=self.connection.features.can_rollback_ddl): + with transaction.atomic(using=self.connection.alias, savepoint=self.connection.features.can_rollback_ddl): with self.connection.cursor() as cursor: for sql in sql_list: cursor.execute(sql) diff --git a/tests/backends/base/test_operations.py b/tests/backends/base/test_operations.py index 0485fe8465..b0ffe958c8 100644 --- a/tests/backends/base/test_operations.py +++ b/tests/backends/base/test_operations.py @@ -172,7 +172,7 @@ class SqlFlushTests(TransactionTestCase): reset_sequences=True, allow_cascade=True, ) - connection.ops.execute_sql_flush(connection.alias, sql_list) + connection.ops.execute_sql_flush(sql_list) with transaction.atomic(): self.assertIs(Author.objects.exists(), False) diff --git a/tests/backends/tests.py b/tests/backends/tests.py index d6c2331378..40fc6de7fc 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -162,7 +162,7 @@ class LongNameTest(TransactionTestCase): VLM_m2m._meta.db_table, ] sql_list = connection.ops.sql_flush(no_style(), tables, reset_sequences=True) - connection.ops.execute_sql_flush(connection.alias, sql_list) + connection.ops.execute_sql_flush(sql_list) class SequenceResetTest(TestCase):