[Django] #17242: Kwargs are not in the context if you inherit from BaseListView or it's subclasses

18 views
Skip to first unread message

Django

unread,
Nov 16, 2011, 5:53:20 PM11/16/11
to django-...@googlegroups.com
#17242: Kwargs are not in the context if you inherit from BaseListView or it's
subclasses
-------------------------+-------------------------------------------------
Reporter: Fact | Owner: nobody
Fiber | Status: new
Type: Bug | Version: SVN
Component: Generic | Keywords: generic views list baselistview
views | kwargs
Severity: Normal | Has patch: 1
Triage Stage: | UI/UX: 0
Unreviewed |
Easy pickings: 1 |
-------------------------+-------------------------------------------------
**Description**:

The problem occurs when you inherit from BaseListView (or a view that
inherits from it) and you assume that context contains kwargs. This is a
fair assumption as MultipleObjectMixin.get_context_data() contains:

{{{
context.update(kwargs)
}}}

Kwargs should be passed to self.get_context_data() in BaseListView and
they're not. Therefore the mentioned line of code code in
MultipleObjectMixin doesn't have any effect.

This looks like a bug as MultipleObjectMixin.get_context_data() which is
exactly the one called in BaseListView uses kwargs to update the context,
but the kwargs are not passed so this breaks the chain.

**Steps to reproduce**:

* Inherit from BaseListView (or its subclasses, e.g. ListView).
* Update kwargs in your view
* Kwargs should be available in the context

**Proposed solution:**

BaseListView's get() should pass kwargs to get_context_data()

**Patch:**

The proposed patch is attached

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

Django

unread,
Nov 17, 2011, 4:47:41 PM11/17/11
to django-...@googlegroups.com
#17242: Kwargs are not in the context if you inherit from BaseListView or it's
subclasses
-------------------------------------+-------------------------------------
Reporter: Fact Fiber | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: SVN
Severity: Normal | Resolution:
Keywords: generic views list | Triage Stage: Accepted
baselistview kwargs | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by ptone):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

This is not exactly a duplicate of #16074, but is closely related, and
should probably be fixed in the work on that ticket - I will reference
this one there.

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

Django

unread,
Dec 12, 2011, 12:05:37 AM12/12/11
to django-...@googlegroups.com
#17242: Kwargs are not in the context if you inherit from BaseListView or it's
subclasses
-------------------------------------+-------------------------------------
Reporter: Fact Fiber | Owner: nobody
Type: Bug | Status: closed
Component: Generic views | Version: SVN
Severity: Normal | Resolution: invalid
Keywords: generic views list | Triage Stage: Accepted
baselistview kwargs | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by ptone):

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


Comment:

Looking at this again now - I actually think this is invalid.

There is confusion here about two different sets of kwargs - one is kwargs
being passed directly to the "get_context_data" method, the other is
kwargs being passed to the get method

There is no expectation that kwargs passed to the get method (from the
URLconf) are automatically to be inserted into the context.

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

Django

unread,
Dec 12, 2011, 12:22:51 AM12/12/11
to django-...@googlegroups.com
#17242: Kwargs are not in the context if you inherit from BaseListView or it's
subclasses
-------------------------------------+-------------------------------------
Reporter: Fact Fiber | Owner: nobody
Type: Bug | Status: closed
Component: Generic views | Version: SVN
Severity: Normal | Resolution: invalid
Keywords: generic views list | Triage Stage: Accepted
baselistview kwargs | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by ptone):

I do see this pattern of passing the get kwargs to get_context_data in
TemplateView - but I think that is a bug there and will open a ticket for
that

--
Ticket URL: <https://code.djangoproject.com/ticket/17242#comment:3>

Django

unread,
Jul 1, 2022, 6:20:39 PM7/1/22
to django-...@googlegroups.com
#17242: Kwargs are not in the context if you inherit from BaseListView or it's
subclasses
-------------------------------------+-------------------------------------
Reporter: Fact Fiber | Owner: nobody
Type: Bug | Status: closed
Component: Generic views | Version: dev

Severity: Normal | Resolution: invalid
Keywords: generic views list | Triage Stage: Accepted
baselistview kwargs |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Following up on the last comment, there's no plan to stop `TemplateView`
from putting `kwargs` in the context as per #19878 (wontfix).

--
Ticket URL: <https://code.djangoproject.com/ticket/17242#comment:4>

Reply all
Reply to author
Forward
0 new messages