Opened 5 years ago

Closed 5 years ago

Last modified 5 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: master
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



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:


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()


The proposed patch is attached

Attachments (1)

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

Download all attachments as: .zip

Change History (4)

Changed 5 years ago by Fact Fiber

Attachment: django_base_list_view.patch added

Proposed patch

comment:1 Changed 5 years ago by Preston Holmes

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
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 Changed 5 years ago by Preston Holmes

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 Changed 5 years ago by Preston Holmes

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

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