Fixed #29307 -- Fixed inspectdb import paths for django.contrib.postgres fields.

Thanks erindy for the report.
This commit is contained in:
Alasdair Nicol 2018-04-09 16:46:31 +00:00 committed by Tim Graham
parent 6a1957bb98
commit 65c44a5c1d
3 changed files with 14 additions and 13 deletions

View File

@ -17,12 +17,12 @@ class PostgresConfig(AppConfig):
for conn in connections.all(): for conn in connections.all():
if conn.vendor == 'postgresql': if conn.vendor == 'postgresql':
conn.introspection.data_types_reverse.update({ conn.introspection.data_types_reverse.update({
3802: 'django.contrib.postgresql.fields.JSONField', 3802: 'django.contrib.postgres.fields.JSONField',
3904: 'django.contrib.postgresql.fields.IntegerRangeField', 3904: 'django.contrib.postgres.fields.IntegerRangeField',
3906: 'django.contrib.postgresql.fields.FloatRangeField', 3906: 'django.contrib.postgres.fields.FloatRangeField',
3910: 'django.contrib.postgresql.fields.DateTimeRangeField', 3910: 'django.contrib.postgres.fields.DateTimeRangeField',
3912: 'django.contrib.postgresql.fields.DateRangeField', 3912: 'django.contrib.postgres.fields.DateRangeField',
3926: 'django.contrib.postgresql.fields.BigIntegerRangeField', 3926: 'django.contrib.postgres.fields.BigIntegerRangeField',
}) })
if conn.connection is not None: if conn.connection is not None:
register_type_handlers(conn) register_type_handlers(conn)

View File

@ -9,4 +9,5 @@ Django 2.0.5 fixes several bugs in 2.0.4.
Bugfixes Bugfixes
======== ========
* ... * Corrected the import paths that ``inspectdb`` generates for
``django.contrib.postgres`` fields (:ticket:`29307`).

View File

@ -22,17 +22,17 @@ class InspectDBTests(PostgreSQLTestCase):
def test_json_field(self): def test_json_field(self):
self.assertFieldsInModel( self.assertFieldsInModel(
'postgres_tests_jsonmodel', 'postgres_tests_jsonmodel',
['field = django.contrib.postgresql.fields.JSONField(blank=True, null=True)'], ['field = django.contrib.postgres.fields.JSONField(blank=True, null=True)'],
) )
def test_range_fields(self): def test_range_fields(self):
self.assertFieldsInModel( self.assertFieldsInModel(
'postgres_tests_rangesmodel', 'postgres_tests_rangesmodel',
[ [
'ints = django.contrib.postgresql.fields.IntegerRangeField(blank=True, null=True)', 'ints = django.contrib.postgres.fields.IntegerRangeField(blank=True, null=True)',
'bigints = django.contrib.postgresql.fields.BigIntegerRangeField(blank=True, null=True)', 'bigints = django.contrib.postgres.fields.BigIntegerRangeField(blank=True, null=True)',
'floats = django.contrib.postgresql.fields.FloatRangeField(blank=True, null=True)', 'floats = django.contrib.postgres.fields.FloatRangeField(blank=True, null=True)',
'timestamps = django.contrib.postgresql.fields.DateTimeRangeField(blank=True, null=True)', 'timestamps = django.contrib.postgres.fields.DateTimeRangeField(blank=True, null=True)',
'dates = django.contrib.postgresql.fields.DateRangeField(blank=True, null=True)', 'dates = django.contrib.postgres.fields.DateRangeField(blank=True, null=True)',
], ],
) )