Code

Opened 4 years ago

Closed 4 years ago

#14532 closed (wontfix)

django.views.generic.list_detail.object_list behavior with callables in extra_context

Reported by: jpileborg Owned by: nobody
Component: Uncategorized Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When using django.views.generic.list_detail.object_list, if it is called with an extra_context parameter that contains an entry with a callable, that callable will be called when copying the extra context to the actual context. This behavior is not always wanted.

In my application, the extra_context contains an object instance in which the class have a custom call method. Since my call method have some required parameters, I will get an error when trying to display the page using the view.

The callable should only be called if it is a function. If the user of object_list wants a callable object in the extra_context, then the user should call the object instance when adding the object to the context dictionary.

I changed the code in django/views/generic/list_detail.py on line 93 to 96 to:

        import types
        if isinstance(value, types.FunctionType):
            c[key] = value()
        else:
            c[key] = value

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

Function-based generic views have been deprecated in favor of class-based generic views. Complications with the interpretations of extra_context are one (of many) reasons for this.

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.