[Django] #21297: CurrentSiteManager returns objects of superclass for models that do not define any additional fields

3 views
Skip to first unread message

Django

unread,
Oct 21, 2013, 10:12:18 AM10/21/13
to django-...@googlegroups.com
#21297: CurrentSiteManager returns objects of superclass for models that do not
define any additional fields
-------------------------------+--------------------
Reporter: dp@… | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.sites | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Suppose I have two models, one inheriting the other:


{{{
class BaseModel(models.Model):
title = models.CharField()
# ...

objects = models.Manager()
on_site = CurrentSiteManager()
}}}


Then I create a subclass:


{{{
class SubModel(BaseModel):
objects = models.Manager()
on_site = CurrentSiteManager()

# ...
}}}


Then calling SubModel.on_site.all() returns a QuerySet containing all
instances of BaseModel on that site. Checking the SQL reveals that that no
table join to the sub_model table occurs.

This can be worked around by instead calling
{{{SubModel.objects.filter(site=settings.SITE_ID)}}}, but I do believe
this to be a bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/21297>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 21, 2013, 10:21:37 AM10/21/13
to django-...@googlegroups.com
#21297: CurrentSiteManager returns objects of superclass for sub-models that do not
define any additional fields
-------------------------------+--------------------------------------

Reporter: dp@… | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.sites | Version: 1.5
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 anonymous):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/21297#comment:1>

Django

unread,
Oct 30, 2013, 11:08:50 AM10/30/13
to django-...@googlegroups.com
#21297: CurrentSiteManager returns objects of superclass for sub-models that do not
define any additional fields
-------------------------------+--------------------------------------
Reporter: dp@… | Owner: nobody
Type: Uncategorized | Status: closed
Component: contrib.sites | Version: 1.5
Severity: Normal | Resolution: needsinfo
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 timo):

* status: new => closed
* resolution: => needsinfo


Comment:

I don't think the use case (subclassing without any additional fields) is
advisable without using
[https://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models
proxy models] -- if there are no fields on `SubModel`, then there's no
reason to join the `sub_model` table. Please reopen this doesn't work for
you.

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

Reply all
Reply to author
Forward
0 new messages