#21297 closed Uncategorized (needsinfo)

CurrentSiteManager returns objects of superclass for sub-models that do not define any additional fields

Reported by: dp@… Owned by: nobody
Component: contrib.sites Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (2)

comment:1 Changed 22 months ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from CurrentSiteManager returns objects of superclass for models that do not define any additional fields to CurrentSiteManager returns objects of superclass for sub-models that do not define any additional fields

comment:2 Changed 21 months ago by timo

  • Resolution set to needsinfo
  • Status changed from new to closed

I don't think the use case (subclassing without any additional fields) is advisable without using 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.

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