Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #21090 -- Allowed backends to provide dotted field path to insp…

…ectdb.
  • Loading branch information...
commit e61cc87129727c66120b67c376feda3533544db1 1 parent abb10db
Michael Manfre authored timgraham committed
7  django/core/management/commands/inspectdb.py
@@ -117,7 +117,12 @@ def handle_inspection(self, options):
117 117
                         if not field_type in ('TextField(', 'CharField('):
118 118
                             extra_params['null'] = True
119 119
 
120  
-                field_desc = '%s = models.%s' % (att_name, field_type)
  120
+                field_desc = '%s = %s%s' % (
  121
+                    att_name,
  122
+                    # Custom fields will have a dotted path
  123
+                    '' if '.' in field_type else 'models.',
  124
+                    field_type,
  125
+                )
121 126
                 if extra_params:
122 127
                     if not field_desc.endswith('('):
123 128
                         field_desc += ', '
24  tests/inspectdb/tests.py
@@ -2,7 +2,7 @@
2 2
 from __future__ import unicode_literals
3 3
 
4 4
 import re
5  
-from unittest import expectedFailure
  5
+from unittest import expectedFailure, skipUnless
6 6
 
7 7
 from django.core.management import call_command
8 8
 from django.db import connection
@@ -162,3 +162,25 @@ def test_managed_models(self):
162 162
         output = out.getvalue()
163 163
         self.longMessage = False
164 164
         self.assertIn("        managed = False", output, msg='inspectdb should generate unmanaged models.')
  165
+
  166
+    @skipUnless(connection.vendor == 'sqlite',
  167
+                         "Only patched sqlite's DatabaseIntrospection.data_types_reverse for this test")
  168
+    def test_custom_fields(self):
  169
+        """
  170
+        Introspection of columns with a custom field (#21090)
  171
+        """
  172
+        out = StringIO()
  173
+        orig_data_types_reverse = connection.introspection.data_types_reverse
  174
+        try:
  175
+            connection.introspection.data_types_reverse = {
  176
+                'text': 'myfields.TextField',
  177
+                'bigint': 'BigIntegerField',
  178
+            }
  179
+            call_command('inspectdb',
  180
+                         table_name_filter=lambda tn: tn.startswith('inspectdb_columntypes'),
  181
+                         stdout=out)
  182
+            output = out.getvalue()
  183
+            self.assertIn("text_field = myfields.TextField()", output)
  184
+            self.assertIn("big_int_field = models.BigIntegerField()", output)
  185
+        finally:
  186
+            connection.introspection.data_types_reverse = orig_data_types_reverse

0 notes on commit e61cc87

Please sign in to comment.
Something went wrong with that request. Please try again.