Code

Opened 2 years ago

Closed 2 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: 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

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 2 years ago.
Proposed patch

Download all attachments as: .zip

Change History (4)

Changed 2 years ago by Fact Fiber

Proposed patch

comment:1 Changed 2 years ago by ptone

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 2 years ago by ptone

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

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 2 years ago 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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.