Opened 13 years ago

Closed 13 years ago

Last modified 2 years ago

#17242 closed Bug (invalid)

Kwargs are not in the context if you inherit from BaseListView or it's subclasses

Reported by: Fact Fiber Owned by: nobody
Component: Generic views Version: dev
Severity: Normal Keywords: generic views list baselistview kwargs
Cc: dev@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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

Attachments (1)

django_base_list_view.patch (662 bytes ) - added by Fact Fiber 13 years ago.
Proposed patch

Download all attachments as: .zip

Change History (5)

by Fact Fiber, 13 years ago

Attachment: django_base_list_view.patch added

Proposed patch

comment:1 by Preston Holmes, 13 years ago

Triage Stage: UnreviewedAccepted

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.

comment:2 by Preston Holmes, 13 years ago

Resolution: invalid
Status: newclosed

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.

comment:3 by Preston Holmes, 13 years ago

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

comment:4 by Tim Graham, 2 years ago

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

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