[Django] #26652: missing _default_manager in model instance

16 views
Skip to first unread message

Django

unread,
May 23, 2016, 4:29:44 AM5/23/16
to django-...@googlegroups.com
#26652: missing _default_manager in model instance
-------------------------------+--------------------
Reporter: rsalmaso | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Given a model

{{{#!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.

Django

unread,
May 23, 2016, 4:30:01 AM5/23/16
to django-...@googlegroups.com
#26652: missing _default_manager in model instance
-------------------------------------+-------------------------------------

Reporter: rsalmaso | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by rsalmaso):

* 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>

Django

unread,
May 26, 2016, 10:13:40 AM5/26/16
to django-...@googlegroups.com
#26652: Model instance no longer has a _default_manager attribute
-------------------------------------+-------------------------------------

Reporter: rsalmaso | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* cc: loic (added)


Comment:

Bisected to ed0ff913c648b16c4471fc9a9441d1ee48cb5420.

--
Ticket URL: <https://code.djangoproject.com/ticket/26652#comment:2>

Django

unread,
May 26, 2016, 10:42:32 AM5/26/16
to django-...@googlegroups.com
#26652: Model instance no longer has a _default_manager attribute
--------------------------------------+------------------------------------
Reporter: rsalmaso | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by loic):

* 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>

Django

unread,
May 26, 2016, 1:41:22 PM5/26/16
to django-...@googlegroups.com
#26652: Model instance no longer has a _default_manager attribute
--------------------------------------+------------------------------------
Reporter: rsalmaso | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
May 26, 2016, 1:54:49 PM5/26/16
to django-...@googlegroups.com
#26652: Model instance no longer has a _default_manager attribute
--------------------------------------+------------------------------------
Reporter: rsalmaso | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by rsalmaso):

Ok, thanks.
I'll open a ticket on django-paypal.

--
Ticket URL: <https://code.djangoproject.com/ticket/26652#comment:5>

Django

unread,
May 27, 2016, 10:36:23 AM5/27/16
to django-...@googlegroups.com
#26652: Model instance no longer has a _default_manager attribute
--------------------------------------+------------------------------------
Reporter: rsalmaso | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.10
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
May 27, 2016, 10:36:47 AM5/27/16
to django-...@googlegroups.com
#26652: Model instance no longer has a _default_manager attribute
--------------------------------------+------------------------------------
Reporter: rsalmaso | Owner: nobody

Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.10
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages