Commit 4fd264b6 authored by Tim Graham's avatar Tim Graham
Browse files

Refs #24351 -- Removed support for the old allow_migrate() signature per deprecation timeline.

parent c4e2e9de
Loading
Loading
Loading
Loading
+1 −23
Original line number Diff line number Diff line
import inspect
import os
import pkgutil
import warnings
from importlib import import_module
from threading import local

@@ -9,7 +7,6 @@ from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils import six
from django.utils._os import npath, upath
from django.utils.deprecation import RemovedInDjango110Warning
from django.utils.functional import cached_property
from django.utils.module_loading import import_string

@@ -298,25 +295,6 @@ class ConnectionRouter(object):
                # If the router doesn't have a method, skip to the next one.
                continue

            if six.PY3:
                sig = inspect.signature(router.allow_migrate)
                has_deprecated_signature = not any(
                    p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values()
                )
            else:
                argspec = inspect.getargspec(router.allow_migrate)
                has_deprecated_signature = len(argspec.args) == 3 and not argspec.keywords

            if has_deprecated_signature:
                warnings.warn(
                    "The signature of allow_migrate has changed from "
                    "allow_migrate(self, db, model) to "
                    "allow_migrate(self, db, app_label, model_name=None, **hints). "
                    "Support for the old signature will be removed in Django 1.10.",
                    RemovedInDjango110Warning)
                model = hints.get('model')
                allow = None if model is None else method(db, model)
            else:
            allow = method(db, app_label, **hints)

            if allow is not None:
+0 −6
Original line number Diff line number Diff line
@@ -182,12 +182,6 @@ A database Router is a class that provides up to four methods:
    keys, extra tables, or missing tables if you change it once you have
    applied some migrations.

    .. versionchanged:: 1.8

        The signature of ``allow_migrate`` has changed significantly from previous
        versions. See the :ref:`deprecation notes
        <deprecated-signature-of-allow-migrate>` for more details.

A router doesn't have to provide *all* these methods -- it may omit one
or more of them. If one of the methods is omitted, Django will skip
that router when performing the relevant check.
+0 −32
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ from __future__ import unicode_literals

import datetime
import pickle
import warnings
from operator import attrgetter

from django.contrib.auth.models import User
@@ -12,7 +11,6 @@ from django.db import DEFAULT_DB_ALIAS, connections, router, transaction
from django.db.models import signals
from django.db.utils import ConnectionRouter
from django.test import SimpleTestCase, TestCase, override_settings
from django.utils.encoding import force_text
from django.utils.six import StringIO

from .models import Book, Person, Pet, Review, UserProfile
@@ -1062,36 +1060,6 @@ class RouterTestCase(TestCase):
            self.assertTrue(router.allow_migrate_model('other', User))
            self.assertTrue(router.allow_migrate_model('other', Book))

    def test_migrate_legacy_router(self):
        class LegacyRouter(object):
            def allow_migrate(self, db, model):
                """
                Deprecated allow_migrate signature should trigger
                RemovedInDjango110Warning.
                """
                assert db == 'default'
                assert model is User
                return True

        with override_settings(DATABASE_ROUTERS=[LegacyRouter()]):
            with warnings.catch_warnings(record=True) as recorded:
                warnings.filterwarnings('always')

                msg = (
                    "The signature of allow_migrate has changed from "
                    "allow_migrate(self, db, model) to "
                    "allow_migrate(self, db, app_label, model_name=None, **hints). "
                    "Support for the old signature will be removed in Django 1.10."
                )

                self.assertTrue(router.allow_migrate_model('default', User))
                self.assertEqual(force_text(recorded.pop().message), msg)

                self.assertEqual(recorded, [])

                self.assertTrue(router.allow_migrate('default', 'app_label'))
                self.assertEqual(force_text(recorded.pop().message), msg)

    def test_partial_router(self):
        "A router can choose to implement a subset of methods"
        dive = Book.objects.using('other').create(title="Dive into Python",