#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 by , 9 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|
comment:2 by , 8 years ago
Cc: | added |
---|---|
Summary: | missing _default_manager in model instance → Model instance no longer has a _default_manager attribute |
comment:3 by , 8 years ago
Component: | Database layer (models, ORM) → Documentation |
---|---|
Easy pickings: | set |
Needs documentation: | set |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/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 move the properties from ModelBase
to models.Model
, but I don't think we should.
Bisected to ed0ff913c648b16c4471fc9a9441d1ee48cb5420.