Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#26652 closed Cleanup/optimization (fixed)

Model instance no longer has a _default_manager attribute

Reported by: Raffaele Salmaso Owned by: nobody
Component: Documentation Version: 1.10
Severity: Normal Keywords:
Cc: Loic Bistuer Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Given a model

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

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

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)

Change History (7)

comment:1 Changed 3 years ago by Raffaele Salmaso

Component: UncategorizedDatabase layer (models, ORM)

comment:2 Changed 3 years ago by Tim Graham

Cc: Loic Bistuer added
Summary: missing _default_manager in model instanceModel instance no longer has a _default_manager attribute

comment:3 Changed 3 years ago by Loic Bistuer

Component: Database layer (models, ORM)Documentation
Easy pickings: set
Needs documentation: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Managers were never intended to be accessible on model instances, we even 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 redeclare the properties from ModelBase on models.Model, but I don't think we should.

Last edited 3 years ago by Loic Bistuer (previous) (diff)

comment:4 Changed 3 years ago by Tim Graham

Has patch: set
Needs documentation: unset

comment:5 Changed 3 years ago by Raffaele Salmaso

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

comment:6 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 0e7e47b5:

Fixed #26652 -- Documented removal of model instance _(default/base)_manager attributes.

comment:7 Changed 3 years ago by Tim Graham <timograham@…>

In 9985544:

[1.10.x] Fixed #26652 -- Documented removal of model instance _(default/base)_manager attributes.

Backport of 0e7e47b5d7123441efc03545da59a6cd581c04b1 from master

Note: See TracTickets for help on using tickets.
Back to Top