Repository: django-extensions/django-extensions

Issue:
sqldiff: Workaround fixed upstream, how to proceed
In the `sqldiff` command, there is a workaround for the MySQL backend that reads (`sqldiff.py:619`):

```
            if db_data_type == 'integer' and description[1] == FIELD_TYPE.SHORT:
                parts.insert(0, 'smallint')
                db_type = ' '.join(parts)
```

This workaround was to compensate for the fact that the MySQL db backend was not previously able to introspect database type `SHORT`. As of [f0d3dd4f04efa49e0b58da4847cb89770b59d4a8](https://github.com/django/django/commit/f0d3dd4f04efa49e0b58da4847cb89770b59d4a8), it now can.

So the workaround is redundant and obsolete _once_ the commit is in a release. But, django-extensions supports Django 1.4. This fix will never be in version 1.4. So I am not sure what the correct procedure is for deleting the workaround.



Discussion:
Django 1.4 is a "LTS" (kinda start to hate that acronym :) ) release and it going to be with us `until at least March 2015`. https://docs.djangoproject.com/en/dev/internals/release-process/#long-term-support-lts-releases

Couldn't we use the features flag from the MySQL backend to check for its support ? 
And put the workaround behind a `if not connection.features.can_introspect_small_integer_field` check.

Maybe also add a DeprecationWarning to it, and put some version on it when we don't want to support it at all in Django-Extensions anymore.

That way at least its more isolated and easier to remove when 1.4 support ends. (Or if we decide to drop support earlier)


Resolving patch:
diff --git a/django_extensions/management/commands/sqldiff.py b/django_extensions/management/commands/sqldiff.py
--- a/django_extensions/management/commands/sqldiff.py
+++ b/django_extensions/management/commands/sqldiff.py
@@ -22,6 +22,7 @@
 
 import six
 import sys
+import warnings
 from optparse import make_option
 from django.core.management.base import BaseCommand
 from django.core.management import sql as _sql
@@ -558,6 +559,13 @@ def __init__(self, app_models, options):
         super(MySQLDiff, self).__init__(app_models, options)
         self.auto_increment = set()
         self.load_auto_increment()
+        if not getattr(connection.features, 'can_introspect_small_integer_field', False):
+            from MySQLdb.constants import FIELD_TYPE
+            warnings.warn(
+                'Django version < 1.8 does not support MySQL small ' +
+                'integer introspection, adding override',
+                DeprecationWarning)
+            self.DATA_TYPES_REVERSE_OVERRIDE[FIELD_TYPE.SHORT] = 'SmallIntegerField'
 
     def load_null(self):
         tablespace = 'public'
@@ -616,9 +624,6 @@ def get_field_db_type(self, description, field=None, table_name=None):
             # just convert it back to it's proper type, a bool is a bool and nothing else.
             if db_type == 'integer' and description[1] == FIELD_TYPE.TINY and description[4] == 1:
                 db_type = 'bool'
-            if db_data_type == 'integer' and description[1] == FIELD_TYPE.SHORT:
-                parts.insert(0, 'smallint')
-                db_type = ' '.join(parts)
             if (table_name, field.column) in self.auto_increment:
                 db_type += ' AUTO_INCREMENT'
         return db_type


Test patch: