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

Confusion regarding @view_config return value usage #666

Open
wichert opened this Issue Aug 28, 2012 · 8 comments

Comments

Projects
None yet
5 participants
@wichert
Member

wichert commented Aug 28, 2012

I have an existing view function that I am trying expose for another object as well. The original is defined like this:

@view_config(route_name='celebrity-style-link-search', context=CelebrityStyle,
        renderer='json', permission='authenticated')
def link_search(context, request):
    ....

To expose it for a different class as well I tried to call view_config directly:

magazine_link_search = (view_config(route_name='magazine-page-link-search',
        context=MagazinePage, renderer='json', permission='authenticated')
        (link_search))

That result in an error that the view conflicts with itself:

pyramid.exceptions.ConfigurationConflictError: Conflicting configuration actions
  For: ('view', <class 'customer.site.model.magazine.MagazinePage'>, '', None, <InterfaceClass pyramid.interfaces.IView>, None, None, None, 'magazine-page-link-search', None, False, None, None, None, None)
    ('/home/wichert/Work/customer.admin/src/customer/admin/ui/magazine.py', 149, '<module>', '(link_search))')
    ('/home/wichert/Work/customer.admin/src/customer/admin/ui/magazine.py', 149, '<module>', '(link_search))')

This appears to be due to the assignment. If I rewrite the code to remove the assignment to this:

(view_config(route_name='magazine-page-link-search',
        context=MagazinePage, renderer='json', permission='authenticated')
        (link_search))

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?

@mcdonc

This comment has been minimized.

Show comment
Hide comment
@mcdonc

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.

Member

mcdonc commented Aug 10, 2013

I'm marking this as "sprintable" so that someone can verify that Wiggy's example breaks (or doesn't) with the most recent venusian.

@witsch

This comment has been minimized.

Show comment
Hide comment
@witsch

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...

Member

witsch commented Aug 17, 2013

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...

@witsch

This comment has been minimized.

Show comment
Hide comment
@witsch

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')
Member

witsch commented Aug 17, 2013

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')
@witsch

This comment has been minimized.

Show comment
Hide comment
@witsch

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! ;)

Member

witsch commented Aug 19, 2013

@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! ;)

@wichert

This comment has been minimized.

Show comment
Hide comment
@wichert

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.

Member

wichert commented Aug 19, 2013

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.

@pauleveritt

This comment has been minimized.

Show comment
Hide comment
@pauleveritt

pauleveritt Apr 15, 2015

Member

@wichert I'm doing some housecleaning, is this ticket still worth keeping open?

Member

pauleveritt commented Apr 15, 2015

@wichert I'm doing some housecleaning, is this ticket still worth keeping open?

@wichert

This comment has been minimized.

Show comment
Hide comment
@wichert

wichert Apr 15, 2015

Member

I do see some value in keeping this open, albeit at a very low priority.

Member

wichert commented Apr 15, 2015

I do see some value in keeping this open, albeit at a very low priority.

@mmerickel

This comment has been minimized.

Show comment
Hide comment
@mmerickel

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.

Member

mmerickel commented Jun 15, 2015

If this is really an issue then it should be reported to venusian. If someone does this we can close the issue here.

@mmerickel mmerickel removed the sprintable label Jul 17, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment