#34165: migrate management command does not respect database parameter when
adding
Permissions.
------------------------------+------------------------------------
Reporter: Vasanth | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Comment (by David Wobrock):
Replying to [comment:3 Mariusz Felisiak]:
> Thanks for this report, it's related with adding missing permissions. I
was able to fix this by setting `_state.db`, however I'm not convinced
that it's the best solution:
> {{{#!diff
> diff --git a/django/contrib/auth/management/__init__.py
b/django/contrib/auth/management/__init__.py
> index 0b5a982617..27fe0df1d7 100644
> --- a/django/contrib/auth/management/__init__.py
> +++ b/django/contrib/auth/management/__init__.py
> @@ -94,12 +94,15 @@ def create_permissions(
> )
> .values_list("content_type", "codename")
> )
> -
> - perms = [
> - Permission(codename=codename, name=name, content_type=ct)
> - for ct, (codename, name) in searched_perms
> - if (ct.pk, codename) not in all_perms
> - ]
> + perms = []
> + for ct, (codename, name) in searched_perms:
> + if (ct.pk, codename) not in all_perms:
> + permission = Permission()
> + permission._state.db = using
> + permission.codename = codename
> + permission.name = name
> + permission.content_type = ct
> + perms.append(permission)
> Permission.objects.using(using).bulk_create(perms)
> if verbosity >= 2:
> for perm in perms:
>
> }}}
>
> Partly related to #29843.
I think `bulk_create` already sets the `_state.db` to the value passed in
`.using()`, right?
Or is it in `bulk_create` that we require `_state.db` to be set earlier?
In which case, we could perhaps change something inside of this method.
Replying to [comment:5 Vasanth]:
> After diving a bit deeper it turned out that the issue was with one of
the libraries in my project which was not adapted for multi-DB. I've made
a PR with changes on the django-admin-interface which resolved my issue.
So would it be relevant to close the issue or is the bug really related to
Django itself?
--
Ticket URL: <https://code.djangoproject.com/ticket/34165#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018529b69282-aa5076be-10e7-4a6f-94c8-56e0b04029e0-000000%40eu-central-1.amazonses.com.