Fixed #21477 -- Renamed db to using in pre/post_migrate signals.
This commit is contained in:
parent
d674fe6dee
commit
d562527a16
|
@ -60,7 +60,7 @@ def _check_permission_clashing(custom, builtin, ctype):
|
|||
pool.add(codename)
|
||||
|
||||
|
||||
def create_permissions(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_ALIAS, **kwargs):
|
||||
def create_permissions(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs):
|
||||
if not app_config.models_module:
|
||||
return
|
||||
|
||||
|
@ -69,7 +69,7 @@ def create_permissions(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_
|
|||
except LookupError:
|
||||
return
|
||||
|
||||
if not router.allow_migrate(db, Permission):
|
||||
if not router.allow_migrate(using, Permission):
|
||||
return
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
@ -82,7 +82,7 @@ def create_permissions(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_
|
|||
for klass in app_config.get_models():
|
||||
# Force looking up the content types in the current database
|
||||
# before creating foreign keys to them.
|
||||
ctype = ContentType.objects.db_manager(db).get_for_model(klass)
|
||||
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
|
||||
ctypes.add(ctype)
|
||||
for perm in _get_all_permissions(klass._meta, ctype):
|
||||
searched_perms.append((ctype, perm))
|
||||
|
@ -90,7 +90,7 @@ def create_permissions(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_
|
|||
# Find all the Permissions that have a content_type for a model we're
|
||||
# looking for. We don't need to check for codenames since we already have
|
||||
# a list of the ones we're going to create.
|
||||
all_perms = set(Permission.objects.using(db).filter(
|
||||
all_perms = set(Permission.objects.using(using).filter(
|
||||
content_type__in=ctypes,
|
||||
).values_list(
|
||||
"content_type", "codename"
|
||||
|
@ -113,13 +113,13 @@ def create_permissions(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_
|
|||
verbose_name_max_length,
|
||||
)
|
||||
)
|
||||
Permission.objects.using(db).bulk_create(perms)
|
||||
Permission.objects.using(using).bulk_create(perms)
|
||||
if verbosity >= 2:
|
||||
for perm in perms:
|
||||
print("Adding permission '%s'" % perm)
|
||||
|
||||
|
||||
def create_superuser(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_ALIAS, **kwargs):
|
||||
def create_superuser(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs):
|
||||
try:
|
||||
apps.get_model('auth', 'Permission')
|
||||
except LookupError:
|
||||
|
@ -139,7 +139,7 @@ def create_superuser(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_AL
|
|||
confirm = input('Please enter either "yes" or "no": ')
|
||||
continue
|
||||
if confirm == 'yes':
|
||||
call_command("createsuperuser", interactive=True, database=db)
|
||||
call_command("createsuperuser", interactive=True, database=using)
|
||||
break
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.utils import six
|
|||
from django.utils.six.moves import input
|
||||
|
||||
|
||||
def update_contenttypes(app_config, verbosity=2, interactive=True, db=DEFAULT_DB_ALIAS, **kwargs):
|
||||
def update_contenttypes(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs):
|
||||
"""
|
||||
Creates content types for models in the given app, removing any model
|
||||
entries that no longer have a matching model class.
|
||||
|
@ -19,7 +19,7 @@ def update_contenttypes(app_config, verbosity=2, interactive=True, db=DEFAULT_DB
|
|||
except LookupError:
|
||||
return
|
||||
|
||||
if not router.allow_migrate(db, ContentType):
|
||||
if not router.allow_migrate(using, ContentType):
|
||||
return
|
||||
|
||||
ContentType.objects.clear_cache()
|
||||
|
@ -36,7 +36,7 @@ def update_contenttypes(app_config, verbosity=2, interactive=True, db=DEFAULT_DB
|
|||
# Get all the content types
|
||||
content_types = dict(
|
||||
(ct.model, ct)
|
||||
for ct in ContentType.objects.using(db).filter(app_label=app_label)
|
||||
for ct in ContentType.objects.using(using).filter(app_label=app_label)
|
||||
)
|
||||
to_remove = [
|
||||
ct
|
||||
|
@ -53,7 +53,7 @@ def update_contenttypes(app_config, verbosity=2, interactive=True, db=DEFAULT_DB
|
|||
for (model_name, model) in six.iteritems(app_models)
|
||||
if model_name not in content_types
|
||||
]
|
||||
ContentType.objects.using(db).bulk_create(cts)
|
||||
ContentType.objects.using(using).bulk_create(cts)
|
||||
if verbosity >= 2:
|
||||
for ct in cts:
|
||||
print("Adding content type '%s | %s'" % (ct.app_label, ct.model))
|
||||
|
|
|
@ -217,7 +217,7 @@ def emit_pre_migrate_signal(create_models, verbosity, interactive, db):
|
|||
app_config=app_config,
|
||||
verbosity=verbosity,
|
||||
interactive=interactive,
|
||||
db=db)
|
||||
using=db)
|
||||
# For backwards-compatibility -- remove in Django 1.9.
|
||||
models.signals.pre_syncdb.send(
|
||||
sender=app_config.models_module,
|
||||
|
@ -240,7 +240,7 @@ def emit_post_migrate_signal(created_models, verbosity, interactive, db):
|
|||
app_config=app_config,
|
||||
verbosity=verbosity,
|
||||
interactive=interactive,
|
||||
db=db)
|
||||
using=db)
|
||||
# For backwards-compatibility -- remove in Django 1.9.
|
||||
models.signals.post_syncdb.send(
|
||||
sender=app_config.models_module,
|
||||
|
|
|
@ -62,8 +62,8 @@ post_delete = ModelSignal(providing_args=["instance", "using"], use_caching=True
|
|||
|
||||
m2m_changed = ModelSignal(providing_args=["action", "instance", "reverse", "model", "pk_set", "using"], use_caching=True)
|
||||
|
||||
pre_migrate = Signal(providing_args=["app_config", "verbosity", "interactive", "db"])
|
||||
post_migrate = Signal(providing_args=["app_config", "verbosity", "interactive", "db"])
|
||||
pre_migrate = Signal(providing_args=["app_config", "verbosity", "interactive", "using"])
|
||||
post_migrate = Signal(providing_args=["app_config", "verbosity", "interactive", "using"])
|
||||
|
||||
pre_syncdb = Signal(providing_args=["app", "create_models", "verbosity", "interactive", "db"])
|
||||
post_syncdb = Signal(providing_args=["class", "app", "created_models", "verbosity", "interactive", "db"])
|
||||
|
|
|
@ -408,7 +408,7 @@ Arguments sent with this signal:
|
|||
For example, the :mod:`django.contrib.auth` app only prompts to create a
|
||||
superuser when ``interactive`` is ``True``.
|
||||
|
||||
``db``
|
||||
``using``
|
||||
The alias of database on which a command will operate.
|
||||
|
||||
pre_syncdb
|
||||
|
@ -459,7 +459,7 @@ Arguments sent with this signal:
|
|||
For example, the :mod:`django.contrib.auth` app only prompts to create a
|
||||
superuser when ``interactive`` is ``True``.
|
||||
|
||||
``db``
|
||||
``using``
|
||||
The alias of database on which a command will operate.
|
||||
|
||||
post_migrate
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.utils import six
|
|||
|
||||
|
||||
APP_CONFIG = apps.get_app_config('migrate_signals')
|
||||
PRE_MIGRATE_ARGS = ['app_config', 'verbosity', 'interactive', 'db']
|
||||
PRE_MIGRATE_ARGS = ['app_config', 'verbosity', 'interactive', 'using']
|
||||
MIGRATE_DATABASE = 'default'
|
||||
MIGRATE_VERBOSITY = 1
|
||||
MIGRATE_INTERACTIVE = False
|
||||
|
@ -35,7 +35,7 @@ class OneTimeReceiver(object):
|
|||
def __call__(self, signal, sender, **kwargs):
|
||||
# Although test runner calls migrate for several databases,
|
||||
# testing for only one of them is quite sufficient.
|
||||
if kwargs['db'] == MIGRATE_DATABASE:
|
||||
if kwargs['using'] == MIGRATE_DATABASE:
|
||||
self.call_counter = self.call_counter + 1
|
||||
self.call_args = kwargs
|
||||
# we need to test only one call of migrate
|
||||
|
@ -74,4 +74,4 @@ class MigrateSignalTests(TestCase):
|
|||
self.assertEqual(args['app_config'], APP_CONFIG)
|
||||
self.assertEqual(args['verbosity'], MIGRATE_VERBOSITY)
|
||||
self.assertEqual(args['interactive'], MIGRATE_INTERACTIVE)
|
||||
self.assertEqual(args['db'], 'default')
|
||||
self.assertEqual(args['using'], 'default')
|
||||
|
|
Loading…
Reference in New Issue