From c24a2e6cbd391c0d6359fce00e6390de9af9d2d0 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 13 Nov 2014 17:35:33 +0100 Subject: [PATCH] Fixed #23765 -- Removed BooleanField default check which often yielded false positives. --- django/core/checks/__init__.py | 1 - .../core/checks/compatibility/django_1_6_0.py | 41 ------------------- docs/ref/checks.txt | 3 +- tests/check_framework/models.py | 5 --- tests/check_framework/tests.py | 30 +------------- 5 files changed, 3 insertions(+), 77 deletions(-) delete mode 100644 django/core/checks/compatibility/django_1_6_0.py diff --git a/django/core/checks/__init__.py b/django/core/checks/__init__.py index f3e38448d6..e446bdc099 100644 --- a/django/core/checks/__init__.py +++ b/django/core/checks/__init__.py @@ -7,7 +7,6 @@ from .messages import (CheckMessage, from .registry import register, run_checks, tag_exists, Tags # Import these to force registration of checks -import django.core.checks.compatibility.django_1_6_0 # NOQA import django.core.checks.compatibility.django_1_7_0 # NOQA import django.core.checks.model_checks # NOQA import django.core.checks.security.base # NOQA diff --git a/django/core/checks/compatibility/django_1_6_0.py b/django/core/checks/compatibility/django_1_6_0.py deleted file mode 100644 index 513169babe..0000000000 --- a/django/core/checks/compatibility/django_1_6_0.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- encoding: utf-8 -*- -from __future__ import unicode_literals - -from django.apps import apps - -from .. import Warning, register, Tags - - -@register(Tags.compatibility) -def check_1_6_compatibility(**kwargs): - errors = [] - errors.extend(_check_boolean_field_default_value(**kwargs)) - return errors - - -def _check_boolean_field_default_value(app_configs=None, **kwargs): - """ - Checks if there are any BooleanFields without a default value, & - warns the user that the default has changed from False to None. - """ - from django.db import models - - problem_fields = [ - field - for model in apps.get_models(**kwargs) - if app_configs is None or model._meta.app_config in app_configs - for field in model._meta.local_fields - if isinstance(field, models.BooleanField) and not field.has_default() - ] - - return [ - Warning( - "BooleanField does not have a default value.", - hint=("Django 1.6 changed the default value of BooleanField from False to None. " - "See https://docs.djangoproject.com/en/1.6/ref/models/fields/#booleanfield " - "for more information."), - obj=field, - id='1_6.W002', - ) - for field in problem_fields - ] diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt index 04c7dc4a7d..f1b34fade4 100644 --- a/docs/ref/checks.txt +++ b/docs/ref/checks.txt @@ -168,7 +168,8 @@ that might occur as a result of a version upgrade. * **1_6.W001**: Some project unit tests may not execute as expected. *This check was removed in Django 1.8 due to false positives*. -* **1_6.W002**: ``BooleanField`` does not have a default value. +* **1_6.W002**: ``BooleanField`` does not have a default value. *This + check was removed in Django 1.8 due to false positives*. * **1_7.W001**: Django 1.7 changed the global defaults for the ``MIDDLEWARE_CLASSES.`` ``django.contrib.sessions.middleware.SessionMiddleware``, diff --git a/tests/check_framework/models.py b/tests/check_framework/models.py index f091783098..3b17332411 100644 --- a/tests/check_framework/models.py +++ b/tests/check_framework/models.py @@ -7,8 +7,3 @@ from django.db import models class SimpleModel(models.Model): field = models.IntegerField() manager = models.manager.Manager() - - -class Book(models.Model): - title = models.CharField(max_length=250) - is_published = models.BooleanField(default=False) diff --git a/tests/check_framework/tests.py b/tests/check_framework/tests.py index 43b579d383..db06c138da 100644 --- a/tests/check_framework/tests.py +++ b/tests/check_framework/tests.py @@ -10,17 +10,15 @@ from django.core import checks from django.core.checks import Error, Warning from django.core.checks.model_checks import check_all_models from django.core.checks.registry import CheckRegistry -from django.core.checks.compatibility.django_1_6_0 import check_1_6_compatibility from django.core.checks.compatibility.django_1_7_0 import check_1_7_compatibility from django.core.management.base import CommandError from django.core.management import call_command from django.db import models -from django.db.models.fields import NOT_PROVIDED from django.test import TestCase from django.test.utils import override_settings, override_system_checks from django.utils.encoding import force_text -from .models import SimpleModel, Book +from .models import SimpleModel class DummyObj(object): @@ -114,32 +112,6 @@ class MessageTests(TestCase): self.assertEqual(force_text(e), expected) -class Django_1_6_0_CompatibilityChecks(TestCase): - - @override_settings(TEST_RUNNER='myapp.test.CustomRunner') - def test_boolean_field_default_value(self): - # We patch the field's default value to trigger the warning - boolean_field = Book._meta.get_field('is_published') - old_default = boolean_field.default - try: - boolean_field.default = NOT_PROVIDED - errors = check_1_6_compatibility() - expected = [ - checks.Warning( - 'BooleanField does not have a default value.', - hint=('Django 1.6 changed the default value of BooleanField from False to None. ' - 'See https://docs.djangoproject.com/en/1.6/ref/models/fields/#booleanfield ' - 'for more information.'), - obj=boolean_field, - id='1_6.W002', - ) - ] - self.assertEqual(errors, expected) - finally: - # Restore the ``default`` - boolean_field.default = old_default - - class Django_1_7_0_CompatibilityChecks(TestCase): @override_settings(MIDDLEWARE_CLASSES=('django.contrib.sessions.middleware.SessionMiddleware',))