From 75410228dfd16e49eb3c0ea30b59b4c0d2ea6b03 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Wed, 15 Apr 2020 02:20:46 -0700 Subject: Fixed #31473 -- Made sql_flush() use RESTART IDENTITY to reset sequences on PostgreSQL. The sql_flush() positional argument sequences is replaced by the boolean keyword-only argument reset_sequences. This ensures that the old function signature can't be used by mistake when upgrading Django. When the new argument is True, the sequences of the truncated tables will reset. Using a single boolean value, rather than a list, allows making a binary yes/no choice as to whether to reset all sequences rather than a working on a completely different set. --- tests/backends/base/test_operations.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'tests/backends/base') diff --git a/tests/backends/base/test_operations.py b/tests/backends/base/test_operations.py index 5dff48d44e..0485fe8465 100644 --- a/tests/backends/base/test_operations.py +++ b/tests/backends/base/test_operations.py @@ -43,7 +43,7 @@ class SimpleDatabaseOperationTests(SimpleTestCase): def test_sql_flush(self): msg = 'subclasses of BaseDatabaseOperations must provide a sql_flush() method' with self.assertRaisesMessage(NotImplementedError, msg): - self.ops.sql_flush(None, None, None) + self.ops.sql_flush(None, None) def test_pk_default_value(self): self.assertEqual(self.ops.pk_default_value(), 'DEFAULT') @@ -154,7 +154,7 @@ class SqlFlushTests(TransactionTestCase): available_apps = ['backends'] def test_sql_flush_no_tables(self): - self.assertEqual(connection.ops.sql_flush(no_style(), [], []), []) + self.assertEqual(connection.ops.sql_flush(no_style(), []), []) def test_execute_sql_flush_statements(self): with transaction.atomic(): @@ -169,12 +169,7 @@ class SqlFlushTests(TransactionTestCase): sql_list = connection.ops.sql_flush( no_style(), [Author._meta.db_table, Book._meta.db_table], - [ - { - 'table': Author._meta.db_table, - 'column': Author._meta.pk.db_column, - }, - ], + reset_sequences=True, allow_cascade=True, ) connection.ops.execute_sql_flush(connection.alias, sql_list) @@ -185,3 +180,5 @@ class SqlFlushTests(TransactionTestCase): if connection.features.supports_sequence_reset: author = Author.objects.create(name='F. Scott Fitzgerald') self.assertEqual(author.pk, 1) + book = Book.objects.create(author=author) + self.assertEqual(book.pk, 1) -- cgit v1.3