Ticket #16039: issue-16039.diff

File issue-16039.diff, 3.6 KB (added by Allan Lei <allanlei@…>, 3 years ago)

Changed db argument to keyword arg with default value. Missed a .using()

  • django/contrib/auth/management/__init__.py

    diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
    index b516507..d4ad94f 100644
    a b import unicodedata 
    77from django.contrib.auth import models as auth_app
    88from django.db.models import get_models, signals
    99from django.contrib.auth.models import User
     10from django.db import DEFAULT_DB_ALIAS
    1011
    1112
    1213def _get_permission_codename(action, opts):
    def _get_all_permissions(opts): 
    2122    return perms + list(opts.permissions)
    2223
    2324
    24 def create_permissions(app, created_models, verbosity, **kwargs):
     25def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, **kwargs):
    2526    from django.contrib.contenttypes.models import ContentType
    2627
    2728    app_models = get_models(app)
    def create_permissions(app, created_models, verbosity, **kwargs): 
    3233    # The codenames and ctypes that should exist.
    3334    ctypes = set()
    3435    for klass in app_models:
    35         ctype = ContentType.objects.get_for_model(klass)
     36        ctype = ContentType.objects.db_manager(db).get_for_model(klass)
    3637        ctypes.add(ctype)
    3738        for perm in _get_all_permissions(klass._meta):
    3839            searched_perms.append((ctype, perm))
    def create_permissions(app, created_models, verbosity, **kwargs): 
    4041    # Find all the Permissions that have a context_type for a model we're
    4142    # looking for.  We don't need to check for codenames since we already have
    4243    # a list of the ones we're going to create.
    43     all_perms = set(auth_app.Permission.objects.filter(
     44    all_perms = set(auth_app.Permission.objects.using(db).filter(
    4445        content_type__in=ctypes,
    4546    ).values_list(
    4647        "content_type", "codename"
    def create_permissions(app, created_models, verbosity, **kwargs): 
    5152        for ctype, (codename, name) in searched_perms
    5253        if (ctype.pk, codename) not in all_perms
    5354    ]
    54     auth_app.Permission.objects.bulk_create(objs)
     55    auth_app.Permission.objects.using(db).bulk_create(objs)
    5556    if verbosity >= 2:
    5657        for obj in objs:
    5758            print "Adding permission '%s'" % obj
  • django/contrib/contenttypes/management.py

    diff --git a/django/contrib/contenttypes/management.py b/django/contrib/contenttypes/management.py
    index d47d557..cb46654 100644
    a b  
    11from django.contrib.contenttypes.models import ContentType
    22from django.db.models import get_apps, get_models, signals
    33from django.utils.encoding import smart_unicode
     4from django.db import DEFAULT_DB_ALIAS
    45
    5 def update_contenttypes(app, created_models, verbosity=2, **kwargs):
     6def update_contenttypes(app, created_models, verbosity=2, db=DEFAULT_DB_ALIAS, **kwargs):
    67    """
    78    Creates content types for models in the given app, removing any model
    89    entries that no longer have a matching model class.
    def update_contenttypes(app, created_models, verbosity=2, **kwargs): 
    2021    # Get all the content types
    2122    content_types = dict(
    2223        (ct.model, ct)
    23         for ct in ContentType.objects.filter(app_label=app_label)
     24        for ct in ContentType.objects.using(db).filter(app_label=app_label)
    2425    )
    2526    to_remove = [
    2627        ct
    def update_contenttypes(app, created_models, verbosity=2, **kwargs): 
    2829        if model_name not in app_models
    2930    ]
    3031
    31     cts = ContentType.objects.bulk_create([
     32    cts = ContentType.objects.using(db).bulk_create([
    3233        ContentType(
    3334            name=smart_unicode(model._meta.verbose_name_raw),
    3435            app_label=app_label,
Back to Top