From ec73fd67466e0e4841d9ecd0f217c02ce842d860 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Mon, 28 Apr 2025 23:35:04 -0400 Subject: [5.2.x] Fixed #36358 -- Corrected introspection of composite primary keys on SQLite. Previously, any first field of a composite primary key with type `INTEGER` was incorrectly introspected as an `AutoField` due to SQLite treating `INTEGER PRIMARY KEY` as an alias for the `ROWID`. This change ensures that integer fields in composite PKs are not mistaken for auto-incrementing fields. Thanks Jacob Walls and Sarah Boyce for the reviews. Backport of 07100db6f46255ec6ef70b860495f977473684d6 from main. --- tests/inspectdb/tests.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index c5f4ba4c6c..8c544c58c3 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -628,10 +628,7 @@ class InspectDBTransactionalTests(TransactionTestCase): def test_composite_primary_key(self): out = StringIO() - if connection.vendor == "sqlite": - field_type = connection.features.introspected_field_types["AutoField"] - else: - field_type = connection.features.introspected_field_types["IntegerField"] + field_type = connection.features.introspected_field_types["IntegerField"] call_command("inspectdb", "inspectdb_compositeprimarykeymodel", stdout=out) output = out.getvalue() self.assertIn( @@ -639,8 +636,4 @@ class InspectDBTransactionalTests(TransactionTestCase): output, ) self.assertIn(f"column_1 = models.{field_type}()", output) - self.assertIn( - "column_2 = models.%s()" - % connection.features.introspected_field_types["IntegerField"], - output, - ) + self.assertIn(f"column_2 = models.{field_type}()", output) -- cgit v1.3