#23467: Inconsistent behavior when filtering by inherited models when using a
proxy
model
-------------------------------------+-------------------------------------
Reporter: ajaest | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.6
(models, ORM) | Keywords: inherit, proxy, model,
Severity: Normal | queryset, filter
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Having the following scenario:
{{{
import django.db.models as db_models
class ParentModel(db_models.Model):
pass
class ChildModel(ParentModel):
pass
class ParentProxyModel(ParentModel):
pass
}}}
I can filter the `ParentModel` in terms of existing inheriting children,
but not `ParentProxyModel`. An example:
{{{
Python 2.7.5 (default, Jun 25 2014, 10:19:55)
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> a = ParentModel.objects.create()
>>> b = ChildModel.objects.create()
>>> ParentModel.objects.filter(childmodel=None)
[<ParentModel: ParentModel object>]
>>> ParentProxyModel.objects.filter(childmodel=None)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-
packages/django/db/models/manager.py", line 163, in filter
return self.get_queryset().filter(*args, **kwargs)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-
packages/django/db/models/query.py", line 590, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-
packages/django/db/models/query.py", line 608, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-
packages/django/db/models/sql/query.py", line 1198, in add_q
clause = self._add_q(where_part, used_aliases)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-
packages/django/db/models/sql/query.py", line 1234, in _add_q
current_negated=current_negated)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-
packages/django/db/models/sql/query.py", line 1100, in build_filter
allow_explicit_fk=True)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-
packages/django/db/models/sql/query.py", line 1357, in setup_joins
names, opts, allow_many, allow_explicit_fk)
File "/home/ajaest/Code/pfc/src/.env/lib/python2.7/site-
packages/django/db/models/sql/query.py", line 1277, in names_to_path
"Choices are: %s" % (name, ", ".join(available)))
FieldError: Cannot resolve keyword 'childmodel' into field. Choices are:
id, parentmodel_ptr
>>>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23467>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.206c33fbb445d9dffd6d48aced708329%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.