#32640: Non-manager instance assigned to model class' objects is silently
ignored
-------------------------------------+-------------------------------------
Reporter: Shai Berger | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):
* stage: Unreviewed => Accepted
Comment:
Hi Shai.
I think we might be able to do **something** here…
If you get into
[https://github.com/django/django/blob/3b8527e32b665df91622649550813bb1ec9a9251/django/db/models/base.py#L357-L365
this block where the `objects` manager is automatically added]:
{{{
if not opts.managers:
if any(f.name == 'objects' for f in opts.fields):
raise ValueError(
"Model %s must specify a custom Manager, because it
has a "
"field named 'objects'." % cls.__name__
)
manager = Manager()
manager.auto_created = True
cls.add_to_class('objects', manager)
}}}
…then it seems that any value of `objects` is an error 🤔 — but
particularly if `objects` is a `Manager` **class**.
{{{
>>> from django.db import models
>>> class MyModel(models.Model):
... objects = "not-a-manager"
... class Meta:
... app_label = "testing"
...
>>> MyModel.objects
<django.db.models.manager.Manager object at 0x1020f7520>
}}}
I'd think we could at least warn there, but arguably even raise.
Not sure how far down this road it would be worth going.
--
Ticket URL: <https://code.djangoproject.com/ticket/32640#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.928d867be6b7525282bc305fee9789fc%40djangoproject.com.