{{{#!python
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
}}}
In django < 1.10
{{{#!python
In [1]: from polls.models import Question
In [2]: q = Question.objects.last()
In [3]: Question._default_manager
Out[3]: <django.db.models.manager.Manager at 0x7ff799637f28>
In [4]: q._default_manager
Out[4]: <django.db.models.manager.Manager at 0x7ff799637f28>
}}}
In django >= 1.10
{{{#!python
In [1]: from polls.models import Question
In [2]: q = Question.objects.last()
In [3]: Question._default_manager
Out[3]: <django.db.models.manager.Manager at 0x7f5e0721d4a8>
In [4]: q._default_manager
---------------------------------------------------------------------------
AttributeError Traceback (most recent call
last)
<ipython-input-4-2c5c6f28a506> in <module>()
----> 1 q._default_manager
AttributeError: 'Question' object has no attribute '_default_manager'
In [5]: q._meta.default_manager
Out[5]: <django.db.models.manager.Manager at 0x7f5e0721d4a8>
}}}
It's an intenden behaviour?
If so, it lacks a notice in releases note and/or manager docs.
I found it testing my project with django-paypal
(https://github.com/spookylukey/django-
paypal/blob/79b22278b658b2fc618771ca7c471ea398455147/paypal/standard/helpers.py#L24)
--
Ticket URL: <https://code.djangoproject.com/ticket/26652>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26652#comment:1>
* cc: loic (added)
Comment:
Bisected to ed0ff913c648b16c4471fc9a9441d1ee48cb5420.
--
Ticket URL: <https://code.djangoproject.com/ticket/26652#comment:2>
* component: Database layer (models, ORM) => Documentation
* needs_docs: 0 => 1
* type: Uncategorized => Cleanup/optimization
* easy: 0 => 1
* stage: Unreviewed => Accepted
Comment:
Managers were never intended to be accessible on model instances, we even
[https://github.com/django/django/blob/30d110ef43d8a3c50ea8ec4e4fe49bd2bb859530/django/db/models/manager.py#L186
use a descriptor to prevent that usage] but `_default_manager` somehow
escaped that restriction. I guess we can mention the change in the release
notes.
For completeness I'll mention that if we really wanted these available on
the instance we could just move the properties from `ModelBase` to
`models.Model`, but I don't think we should.
--
Ticket URL: <https://code.djangoproject.com/ticket/26652#comment:3>
* needs_docs: 1 => 0
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/6653 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/26652#comment:4>
Comment (by rsalmaso):
Ok, thanks.
I'll open a ticket on django-paypal.
--
Ticket URL: <https://code.djangoproject.com/ticket/26652#comment:5>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"0e7e47b5d7123441efc03545da59a6cd581c04b1" 0e7e47b5]:
{{{
#!CommitTicketReference repository=""
revision="0e7e47b5d7123441efc03545da59a6cd581c04b1"
Fixed #26652 -- Documented removal of model instance
_(default/base)_manager attributes.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26652#comment:6>
Comment (by Tim Graham <timograham@…>):
In [changeset:"9985544adbdbb4ebae3a19010a0600454117a3a1" 9985544]:
{{{
#!CommitTicketReference repository=""
revision="9985544adbdbb4ebae3a19010a0600454117a3a1"
[1.10.x] Fixed #26652 -- Documented removal of model instance
_(default/base)_manager attributes.
Backport of 0e7e47b5d7123441efc03545da59a6cd581c04b1 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26652#comment:7>