Pylons/pyramid — Issue #397: Set @view_defaults get overridden by default argument values on pyramid.view.view_config class
Author: davidjb
Created: 2012-01-09 05:35:28+00:00
State: open

I'm currently attempting to specify a number of defaults for a given Pyramid view callable (a Class + methods) and it appears that the values I specify using the `@view_defaults` decorate get overridden by the default arguments on the relevant `view_config` object.

My class definition looks like so:

@view_defaults(route_name='profile',
context='myprofiles.models.person.Person',
renderer='templates/profile_listing.pt')
@view_config()
class ProfileView(BaseView):
....
@view_config(name='edit')
def edit(self):
return {'action':'Edit profile'}

and I'd like the `route_name` and `renderer` to be used throughout. However, this doesn't work. It appears the reason for this happens in the `viewdefaults` function (at https://github.com/Pylons/pyramid/blob/master/pyramid/config/views.py#L564): `defaults.update(kw)` (where `defaults` are the view_defaults and `kw` are from view_config. Just before executing line 564, my variables look like this (for the Class-level view):

`print defaults`:
{'permission': None, 'custom_predicates': (), 'accept': None, 'header': None, 'request_type': None, 'http_cache': None, 'decorator': None, 'name': '', 'mapper': None, 'request_param': None, 'attr': None, 'route_name': 'profile', 'wrapper': None, 'xhr': False, 'request_method': None, 'renderer': 'templates/profile_listing.pt', 'context': 'myprofiles.models.person.Person', 'containment': None, 'match_param': None, 'path_info': None}

`print kw` (view_config):
{'accept': None, 'header': None, 'match_param': None, 'renderer': None, 'wrapper': None, 'request_method': None, 'permission': None, 'custom_predicates': (), 'request_type': None, 'http_cache': None, 'decorator': None, 'attr': None, 'mapper': None, 'request_param': None, 'name': '', 'route_name': None, 'xhr': False, 'context': None, 'containment': None, '_info': ('/home/davidjb/buildout/my.profiles_/myprofiles/views.py', 35, '', 'class ProfileView(object):'), 'view': , 'path_info': None}

And after running `defaults.update(kw)` defaults now looks like this:

{'permission': None, 'custom_predicates': (), 'accept': None, 'header': None, 'request_type': None, 'http_cache': None, '_info': ('home/davidjb/buildout/my.profiles_/myprofiles/views.py', 35, '', 'class ProfileView(object):'), 'decorator': None, 'name': '', 'mapper': None, 'request_param': None, 'attr': None, 'route_name': None, 'wrapper': None, 'xhr': False, 'request_method': None, 'renderer': None, 'context': None, 'containment': None, 'match_param': None, 'view': , 'path_info': None}

and in doing so, the defaults for `route_name` , `context` and `renderer` becomes overridden.

The issue appears to stem from the view_config class having default values for its properties and these being passed in within this function: https://github.com/Pylons/pyramid/blob/master/pyramid/view.py#L205

Using Pyramid 1.3a4.