From e071f67b7fb1aa171baf5fb1f57310007cc91ab4 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 6 Jun 2014 00:29:24 +0200 Subject: [PATCH] Replaced an explicit vendor check by a feature flag. Forward-port of c9aedce0 from stable/1.7.x. --- django/db/backends/__init__.py | 3 +++ django/db/backends/sqlite3/base.py | 1 + tests/inspectdb/tests.py | 7 +++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index c3ad179c7a..bcc3979e2b 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -591,6 +591,9 @@ class BaseDatabaseFeatures(object): # Can the backend introspect an BooleanField, instead of an IntegerField? can_introspect_boolean_field = True + # Can the backend introspect an DecimalField, instead of an FloatField? + can_introspect_decimal_field = True + # Can the backend introspect an IPAddressField, instead of an CharField? can_introspect_ip_address_field = False diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 419b394429..e43ea328bf 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -105,6 +105,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): supports_foreign_keys = False supports_check_constraints = False autocommits_when_autocommit_is_off = True + can_introspect_decimal_field = False can_introspect_positive_integer_field = True can_introspect_small_integer_field = True supports_transactions = True diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index d848c137dc..c0babe390e 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -100,13 +100,12 @@ class InspectDBTestCase(TestCase): else: assertFieldType('null_bool_field', "models.IntegerField()") - if connection.vendor == 'sqlite': - # Guessed arguments on SQLite, see #5014 + if connection.features.can_introspect_decimal_field: + assertFieldType('decimal_field', "models.DecimalField(max_digits=6, decimal_places=1)") + else: # Guessed arguments on SQLite, see #5014 assertFieldType('decimal_field', "models.DecimalField(max_digits=10, decimal_places=5) " "# max_digits and decimal_places have been guessed, " "as this database handles decimal fields as float") - else: - assertFieldType('decimal_field', "models.DecimalField(max_digits=6, decimal_places=1)") assertFieldType('float_field', "models.FloatField()")