Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upConfusion regarding @view_config return value usage #666
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mcdonc
Aug 10, 2013
Member
I'm marking this as "sprintable" so that someone can verify that Wiggy's example breaks (or doesn't) with the most recent venusian.
|
I'm marking this as "sprintable" so that someone can verify that Wiggy's example breaks (or doesn't) with the most recent venusian. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
witsch
Aug 17, 2013
Member
how about using
@view_config(route_name='magazine-page-link-search', context=MagazinePage,
renderer='json', permission='authenticated')
def magazine_link_search(context, request):
return link_search(context, request)i know people will probably try to use the decorator directly (causing it to break), but i'd argue that the above is much cleaner to read anyway (so they shouldn't really :)). we're gonna check with the latest venusian nevertheless...
|
how about using @view_config(route_name='magazine-page-link-search', context=MagazinePage,
renderer='json', permission='authenticated')
def magazine_link_search(context, request):
return link_search(context, request)i know people will probably try to use the decorator directly (causing it to break), but i'd argue that the above is much cleaner to read anyway (so they shouldn't really :)). we're gonna check with the latest venusian nevertheless... |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
witsch
Aug 17, 2013
Member
ftr, the issue still occurs with the latest pyramid (@f6ea2275f927e88d43fb2d105bce33d0ece0df16) and venusian (@11857ea4674cb01bf6cc82c6faddd62f3c8b35d1). steps to reproduce are:
- run the following from a pyramid checkout
$ tox -c hacking-tox.ini
$ git clone git@github.com:Pylons/venusian.git
$ cd venusian
$ ../env27/bin/python setup.py develop
$ cd ../env27
- append the line
alias_view = view_config(route_name='bar', renderer='json')(my_view)to hacking/hacking/views.py as well as
config.add_route('bar', '/bar')in hacking/hacking/__init__.py:main()
- run
$ bin/pserve hacking/development.ini
this results in
Traceback (most recent call last):
...
File ".../env27/lib/python2.7/site-packages/pyramid/config/__init__.py", line 1199, in resolveConflicts
raise ConfigurationConflictError(conflicts)
pyramid.exceptions.ConfigurationConflictError: Conflicting configuration actions
For: ('view', None, '', 'bar', 'd41d8cd98f00b204e9800998ecf8427e')
Line 9 of file .../env27/hacking/hacking/views.py:
alias_view = view_config(route_name='bar', renderer='json')(my_view)
Line 9 of file .../env27/hacking/hacking/views.py:
alias_view = view_config(route_name='bar', renderer='json')(my_view)
For: ('view', None, '', 'home', 'd41d8cd98f00b204e9800998ecf8427e')
Line 4 of file .../env27/hacking/hacking/views.py:
@view_config(route_name='home', renderer='templates/mytemplate.pt')
Line 4 of file .../env27/hacking/hacking/views.py:
@view_config(route_name='home', renderer='templates/mytemplate.pt')|
ftr, the issue still occurs with the latest pyramid (@f6ea2275f927e88d43fb2d105bce33d0ece0df16) and venusian (@11857ea4674cb01bf6cc82c6faddd62f3c8b35d1). steps to reproduce are:
alias_view = view_config(route_name='bar', renderer='json')(my_view)to config.add_route('bar', '/bar')in
this results in Traceback (most recent call last):
...
File ".../env27/lib/python2.7/site-packages/pyramid/config/__init__.py", line 1199, in resolveConflicts
raise ConfigurationConflictError(conflicts)
pyramid.exceptions.ConfigurationConflictError: Conflicting configuration actions
For: ('view', None, '', 'bar', 'd41d8cd98f00b204e9800998ecf8427e')
Line 9 of file .../env27/hacking/hacking/views.py:
alias_view = view_config(route_name='bar', renderer='json')(my_view)
Line 9 of file .../env27/hacking/hacking/views.py:
alias_view = view_config(route_name='bar', renderer='json')(my_view)
For: ('view', None, '', 'home', 'd41d8cd98f00b204e9800998ecf8427e')
Line 4 of file .../env27/hacking/hacking/views.py:
@view_config(route_name='home', renderer='templates/mytemplate.pt')
Line 4 of file .../env27/hacking/hacking/views.py:
@view_config(route_name='home', renderer='templates/mytemplate.pt') |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
witsch
Aug 19, 2013
Member
@wiggy, the decorator returns the view function as is, so it's possible to use it multiple times. i've quickly verified it during the sprint party... :)
so, turning your above example into:
@view_config(route_name='magazine-page-link-search', context=MagazinePage,
renderer='json', permission='authenticated')
@view_config(route_name='celebrity-style-link-search', context=CelebrityStyle,
renderer='json', permission='authenticated')
def link_search(context, request):
...should do the trick. and i think it's much more readable, too! ;)
|
@wiggy, the decorator returns the view function as is, so it's possible to use it multiple times. i've quickly verified it during the sprint party... :) so, turning your above example into: @view_config(route_name='magazine-page-link-search', context=MagazinePage,
renderer='json', permission='authenticated')
@view_config(route_name='celebrity-style-link-search', context=CelebrityStyle,
renderer='json', permission='authenticated')
def link_search(context, request):
...should do the trick. and i think it's much more readable, too! ;) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wichert
Aug 19, 2013
Member
I could, but not without making my code ugly: I want to reuse a common view (for example something handle generate CORS OPTION request) in various places close to the right view.
|
I could, but not without making my code ugly: I want to reuse a common view (for example something handle generate CORS OPTION request) in various places close to the right view. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pauleveritt
Apr 15, 2015
Member
@wichert I'm doing some housecleaning, is this ticket still worth keeping open?
|
@wichert I'm doing some housecleaning, is this ticket still worth keeping open? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wichert
Apr 15, 2015
Member
I do see some value in keeping this open, albeit at a very low priority.
|
I do see some value in keeping this open, albeit at a very low priority. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mmerickel
Jun 15, 2015
Member
If this is really an issue then it should be reported to venusian. If someone does this we can close the issue here.
|
If this is really an issue then it should be reported to venusian. If someone does this we can close the issue here. |
wichert commentedAug 28, 2012
I have an existing view function that I am trying expose for another object as well. The original is defined like this:
To expose it for a different class as well I tried to call view_config directly:
That result in an error that the view conflicts with itself:
This appears to be due to the assignment. If I rewrite the code to remove the assignment to this:
thinks work normally. I do not understand why this would break since I am only calling view_config once here. Is this a venusian bug?