1
0
mirror of https://github.com/django/django.git synced 2025-03-28 02:00:45 +00:00

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

This commit is contained in:
Tim Graham 2015-08-12 09:10:39 -04:00
parent c4e2e9de1f
commit 4fd264b6f1
3 changed files with 1 additions and 61 deletions

View File

@ -1,7 +1,5 @@
import inspect
import os import os
import pkgutil import pkgutil
import warnings
from importlib import import_module from importlib import import_module
from threading import local from threading import local
@ -9,7 +7,6 @@ from django.conf import settings
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils import six from django.utils import six
from django.utils._os import npath, upath from django.utils._os import npath, upath
from django.utils.deprecation import RemovedInDjango110Warning
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.module_loading import import_string from django.utils.module_loading import import_string
@ -298,26 +295,7 @@ class ConnectionRouter(object):
# If the router doesn't have a method, skip to the next one. # If the router doesn't have a method, skip to the next one.
continue continue
if six.PY3: allow = method(db, app_label, **hints)
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: if allow is not None:
return allow return allow

View File

@ -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 keys, extra tables, or missing tables if you change it once you have
applied some migrations. 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 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 or more of them. If one of the methods is omitted, Django will skip
that router when performing the relevant check. that router when performing the relevant check.

View File

@ -2,7 +2,6 @@ from __future__ import unicode_literals
import datetime import datetime
import pickle import pickle
import warnings
from operator import attrgetter from operator import attrgetter
from django.contrib.auth.models import User 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.models import signals
from django.db.utils import ConnectionRouter from django.db.utils import ConnectionRouter
from django.test import SimpleTestCase, TestCase, override_settings from django.test import SimpleTestCase, TestCase, override_settings
from django.utils.encoding import force_text
from django.utils.six import StringIO from django.utils.six import StringIO
from .models import Book, Person, Pet, Review, UserProfile 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', User))
self.assertTrue(router.allow_migrate_model('other', Book)) 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): def test_partial_router(self):
"A router can choose to implement a subset of methods" "A router can choose to implement a subset of methods"
dive = Book.objects.using('other').create(title="Dive into Python", dive = Book.objects.using('other').create(title="Dive into Python",