summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2019-01-19 13:35:51 +0000
committerTim Graham <timograham@gmail.com>2019-01-23 13:18:03 -0500
commit0ef997966955223086fa83df96169aa80dec48a4 (patch)
treedf8c7cf142da7e1f1ab65f930027d461401e2272
parent8d01edfa65859d2ad5f91ad74745862d0eb91eb0 (diff)
Fixed #30123 -- Removed tuple support in DatabaseIntrospection.get_field_type().
Support for returning tuples was undocumented and error prone.
-rw-r--r--django/core/management/commands/inspectdb.py6
-rw-r--r--docs/releases/3.0.txt2
-rw-r--r--tests/introspection/tests.py20
3 files changed, 9 insertions, 19 deletions
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index 5cdd52fccf..92f010a064 100644
--- a/django/core/management/commands/inspectdb.py
+++ b/django/core/management/commands/inspectdb.py
@@ -241,12 +241,6 @@ class Command(BaseCommand):
field_type = 'TextField'
field_notes.append('This field type is a guess.')
- # This is a hook for data_types_reverse to return a tuple of
- # (field_type, field_params_dict).
- if type(field_type) is tuple:
- field_type, new_params = field_type
- field_params.update(new_params)
-
# Add max_length for all CharFields.
if field_type == 'CharField' and row.internal_size:
field_params['max_length'] = int(row.internal_size)
diff --git a/docs/releases/3.0.txt b/docs/releases/3.0.txt
index d7643cf3b6..3c75c14d88 100644
--- a/docs/releases/3.0.txt
+++ b/docs/releases/3.0.txt
@@ -211,6 +211,8 @@ backends.
* The second argument of ``DatabaseIntrospection.get_geometry_type()`` is now
the row description instead of the column name.
+* ``DatabaseIntrospection.get_field_type()`` may no longer return tuples.
+
Miscellaneous
-------------
diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py
index 4eb868e907..d851352cae 100644
--- a/tests/introspection/tests.py
+++ b/tests/introspection/tests.py
@@ -76,7 +76,7 @@ class IntrospectionTests(TransactionTestCase):
with connection.cursor() as cursor:
desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table)
self.assertEqual(
- [datatype(r[1], r) for r in desc],
+ [connection.introspection.get_field_type(r[1], r) for r in desc],
[
'AutoField' if connection.features.can_introspect_autofield else 'IntegerField',
'CharField',
@@ -93,7 +93,7 @@ class IntrospectionTests(TransactionTestCase):
with connection.cursor() as cursor:
desc = connection.introspection.get_table_description(cursor, Reporter._meta.db_table)
self.assertEqual(
- [r[3] for r in desc if datatype(r[1], r) == 'CharField'],
+ [r[3] for r in desc if connection.introspection.get_field_type(r[1], r) == 'CharField'],
[30, 30, 254]
)
@@ -110,7 +110,10 @@ class IntrospectionTests(TransactionTestCase):
def test_bigautofield(self):
with connection.cursor() as cursor:
desc = connection.introspection.get_table_description(cursor, City._meta.db_table)
- self.assertIn(connection.features.introspected_big_auto_field_type, [datatype(r[1], r) for r in desc])
+ self.assertIn(
+ connection.features.introspected_big_auto_field_type,
+ [connection.introspection.get_field_type(r[1], r) for r in desc],
+ )
# Regression test for #9991 - 'real' types in postgres
@skipUnlessDBFeature('has_real_datatype')
@@ -119,7 +122,7 @@ class IntrospectionTests(TransactionTestCase):
cursor.execute("CREATE TABLE django_ixn_real_test_table (number REAL);")
desc = connection.introspection.get_table_description(cursor, 'django_ixn_real_test_table')
cursor.execute('DROP TABLE django_ixn_real_test_table;')
- self.assertEqual(datatype(desc[0][1], desc[0]), 'FloatField')
+ self.assertEqual(connection.introspection.get_field_type(desc[0][1], desc[0]), 'FloatField')
@skipUnlessDBFeature('can_introspect_foreign_keys')
def test_get_relations(self):
@@ -208,12 +211,3 @@ class IntrospectionTests(TransactionTestCase):
self.assertEqual(val['orders'], ['ASC'] * len(val['columns']))
indexes_verified += 1
self.assertEqual(indexes_verified, 4)
-
-
-def datatype(dbtype, description):
- """Helper to convert a data type into a string."""
- dt = connection.introspection.get_field_type(dbtype, description)
- if type(dt) is tuple:
- return dt[0]
- else:
- return dt