Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent KeyError when page_template not supplied #42

Merged
merged 1 commit into from
Apr 4, 2013
Merged

Prevent KeyError when page_template not supplied #42

merged 1 commit into from
Apr 4, 2013

Conversation

jnns
Copy link
Contributor

@jnns jnns commented Mar 27, 2013

When page_template is not supplied as a kwarg via .as_View() a KeyError is raised because .pop() is used on a dictionary with no default value specified.

@jnns
Copy link
Contributor Author

jnns commented Mar 31, 2013

Indeed, page_template is passed to get_context_data(). But what if one overwrites the GenericView's get() method? Additionally, the following condition would be useless otherwise because page_template could never be None:

   if page_template is None:
            if hasattr(queryset, 'model'):
                page_template = self.get_page_template(**kwargs)
            else:
                raise ImproperlyConfigured(
                    'AjaxListView requires a page_template')

@frankban
Copy link
Owner

frankban commented Apr 4, 2013

It seems to me that that condition still makes sense, because page_template can be passed and can be None (i.e. when self.page_template is None). However, I see you point re overriding get. I'd like to merge your change, but It's still not clear to me why we should do the same for the queryset. The corresponding Django generic view uses the same logic to populate the context with the queryset, essentially """queryset = kwargs.pop('object_list')""". Could you please explain why do you think that's required or, if I convinced you, change the merge proposal accordingly? After that, I'll merge it and also add a test for the page_template issue.

When `page_template` is not supplied as a kwarg via `.as_View()` a
KeyError is raised because `.pop()` is used on a dictionary with no
default value specified.
@jnns
Copy link
Contributor Author

jnns commented Apr 4, 2013

You're right. It doesn't make sense for queryset so I edited the commit to only add the default None for page_template.

frankban added a commit that referenced this pull request Apr 4, 2013
Prevent KeyError when page_template is not supplied.
@frankban frankban merged commit 9727208 into frankban:master Apr 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants