{{{#!python
...
migrations.AlterModelManagers(
name='some_model',
managers=[
('objects', django.db.models.manager.Manager()),
],
),
}}}
We've never run `AlterModelManagers` in the past. Instead of the Manager
we define being added, the default Manager is being set.
I can add code examples + instructions later
--
Ticket URL: <https://code.djangoproject.com/ticket/26643>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Further investigation shows that if you have a manager without
`use_in_migrations` set, it will explicitly set the default manager in
`AlterModelManagers` instead of the previous behaviour of not creating a
migration at all (ie, the migration treats the model as if no manager has
been set at all).
As such, I'm going to remove the bug label, however it would be good to
mention this in the release notes to avoid questions down the road.
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:1>
* type: Bug => Uncategorized
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:2>
* cc: loic (added)
* keywords: => 1.10
* component: Migrations => Documentation
* type: Uncategorized => Cleanup/optimization
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:3>
Comment (by loic):
Hi cybojenix, could you still provide code examples? I'd like to ensure
it's the ideal behavior.
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:4>
* type: Cleanup/optimization => Bug
* component: Documentation => Migrations
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
I briefly talked to cybojenix on IRC, this sounds like a bug to me.
'''Seen behavior:'''
{{{#!python
class CustomManager(models.Manager):
pass
class Model(models.Model):
objects = CustomManager()
}}}
This creates a migration with a default manager though no manager is
marked with `use_in_migrations = True`.
'''Expected behavior:'''
Unless there's >=1 manager with `use_in_migrations = True` don't actually
''add'' the manager to the state but only ''consider'' it was added. This
prevents unnecessary migrations that don't add anything useful.
Essentially, a ModelState with an empty `managers` dict is the same as
defining a model without setting an explicit manager (neither default nor
a custom one).
----
Marked as release blocker due to unexpected creation of migrations. I'd
have wanted this fixed when I'd have noticed it while reviewing
https://github.com/django/django/pull/6175
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:5>
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/6635
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:6>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:7>
Comment (by schinckel):
I believe reinstating the code at
https://github.com/django/django/commit/ed0ff913c648b16c4471fc9a9441d1ee48cb5420
#diff-c8a3e1d248f8f5b10af7ac5b1d8479f4L516 is sufficient to fix this bug.
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:8>
Comment (by schinckel):
Replying to [comment:8 schinckel]:
> I believe reinstating the code at
https://github.com/django/django/commit/ed0ff913c648b16c4471fc9a9441d1ee48cb5420
#diff-c8a3e1d248f8f5b10af7ac5b1d8479f4L516 is sufficient to fix this bug.
Ah, not quite. This causes a deprecation warning in the manager
inheritance stuff.
Perhaps the check could be included in the autodetector, instead of the
ModelState.
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:9>
* owner: nobody => schinckel
* status: new => assigned
* needs_tests: 0 => 1
Comment:
Okay, I have a patch, but no tests:
https://github.com/schinckel/django/commit/38a0cb2a9bfb4752b661905a2de6278fed9771dd
Should I be creating a PR against 1.10.x, or master?
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:10>
* keywords: 1.10 =>
* version: master => 1.10
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:11>
* needs_better_patch: 1 => 0
* needs_tests: 1 => 0
Comment:
Test is added to the PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:12>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:13>
Comment (by loic):
Latest [https://github.com/django/django/pull/6799 PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:14>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"2eb7cb2fffcc382979d0731370de26b051d04659" 2eb7cb2f]:
{{{
#!CommitTicketReference repository=""
revision="2eb7cb2fffcc382979d0731370de26b051d04659"
Fixed #26643 -- Prevented unnecessary AlterModelManagers operations caused
by the manager inheritance refactor.
This also makes migrations respect the base_manager_name and
default_manager_name model options.
Thanks Anthony King and Matthew Schinckel for the initial patches.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:15>
Comment (by Tim Graham <timograham@…>):
In [changeset:"0f23bcebdfe556711a0463c8775981575c272b79" 0f23bceb]:
{{{
#!CommitTicketReference repository=""
revision="0f23bcebdfe556711a0463c8775981575c272b79"
[1.10.x] Fixed #26643 -- Prevented unnecessary AlterModelManagers
operations caused by the manager inheritance refactor.
This also makes migrations respect the base_manager_name and
default_manager_name model options.
Thanks Anthony King and Matthew Schinckel for the initial patches.
Backport of 2eb7cb2fffcc382979d0731370de26b051d04659 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26643#comment:16>