#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:10 Mariusz Felisiak]: > Replying to [comment:8 David Wobrock]: > > I think `bulk_create` already sets the `_state.db` to the value passed in `.using()`, right? > > Yes, but it's a different issue, strictly related with `Permission` and its `content_type`. `get_content_type()` is trying to find a content type using `obj._state.db` so when we create a `Permission()` without `._state.db` it will first try to find a content type in the default db. Okay, I understand the issue now, thanks for the details!! First thing, it makes me wonder why we require to have a DB attribute set, at a moment where we are not (yet) interacting with the DB. So we are currently checking, when setting the `content_type` FK, that the router allows this relation. I guess one option is to not do that for not- saved model instances. Would it make sense to defer this to when we start interacting with the DB? But it brings a whole other lot of changes and challenges, like changing a deep behaviour of FKs and multi-tenancy :/ Apart from that, if we don't want to set directly the internal attribute `_state.db`, I guess we would need a proper way to pass the `db`/`using` to the model instantiation. What would be the most ''Django-y'' way? - Passing it through the model constructor => this has quite a large impact, as a keyword argument would possibly shadow existing field names: `Permission(..., db=using)`. Quite risky in terms of backward compatibility I guess. - Adding a method to `Model`? Something like: `Permission(...).using(db)`, which could perhaps then be re-used in other places also. What do you think ? :) Or am I missing other solutions? -- Ticket URL: <https://code.djangoproject.com/ticket/34165#comment:11> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/010701852ef6b16c-5086918c-e150-45ed-b179-e9aa00151a69-000000%40eu-central-1.amazonses.com.