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

config.add_view(<instancemethod>) raises AttributeError for __text__ #461

Closed
hlv42 opened this issue Mar 5, 2012 · 1 comment
Closed

Comments

@hlv42
Copy link
Contributor

hlv42 commented Mar 5, 2012

bug

using

config.add_view(self.somemethod, route_name="something")

raises

pyramid.exceptions.ConfigurationExecutionError: <type 'exceptions.AttributeError'>: 'instancemethod' object has no attribute '__text__'
  in:
  Line 14 of file helloworld.bugdemo.py:
    config.add_view(f.hello_world, route_name='hello')

workaround:

a workaround until this is fixed can be done by changing to:
config.add_view(self, attr="somemethod", route_name="something")

sample code:

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

class foo:
        def hello_world(self, root, request):
                return Response('Hello %(name)s!' % request.matchdict)

if __name__ == '__main__':
   config = Configurator()
   f= foo()
   config.add_route('hello', '/hello/{name}')
   config.add_view(f.hello_world, route_name='hello')
   app = config.make_wsgi_app()
   server = make_server('0.0.0.0', 8080, app)
   server.serve_forever()

complete traceback:

Traceback (most recent call last):
  File "helloworld.bugdemo.py", line 15, in <module>
    app = config.make_wsgi_app()
  File "/home/dev/www/env/lib/python2.6/site-packages/pyramid/config/__init__.py", line 921, in make_wsgi_app
    self.commit()
  File "/home/dev/www/env/lib/python2.6/site-packages/pyramid/config/__init__.py", line 594, in commit
    self.action_state.execute_actions(introspector=self.introspector)
  File "/home/dev/www/env/lib/python2.6/site-packages/pyramid/config/__init__.py", line 1049, in execute_actions
    tb)
  File "/home/dev/www/env/lib/python2.6/site-packages/pyramid/config/__init__.py", line 1041, in execute_actions
    callable(*args, **kw)
  File "/home/dev/www/env/lib/python2.6/site-packages/pyramid/config/views.py", line 1087, in register
    derived_view = deriver(view)
  File "/home/dev/www/env/lib/python2.6/site-packages/pyramid/config/views.py", line 142, in __call__
    self.mapped_view(view)))))))))
  File "/home/dev/www/env/lib/python2.6/site-packages/pyramid/config/views.py", line 87, in inner
    wrapper_view = wrapper(self, view)
  File "/home/dev/www/env/lib/python2.6/site-packages/pyramid/config/views.py", line 154, in mapped_view
    mapped_view = mapper(**self.kw)(view)
  File "/home/dev/www/env/lib/python2.6/site-packages/pyramid/config/views.py", line 395, in __call__
    view = self.map_nonclass(view)
  File "/home/dev/www/env/lib/python2.6/site-packages/pyramid/config/views.py", line 426, in map_nonclass
    mapped_view.__text__ = object_description(view)
pyramid.exceptions.ConfigurationExecutionError: <type 'exceptions.AttributeError'>: 'instancemethod' object has no attribute '__text__'
  in:
  Line 14 of file helloworld.bugdemo.py:
    config.add_view(f.hello_world, route_name='hello')
hlv42 pushed a commit to hlv42/pyramid that referenced this issue Mar 5, 2012
- config.add_view() raises an AttributeError for __text__ if the View is an instancemethod.
  added wrapper adding the __text__ attribute if it isnt present yet.
hlv42 added a commit to hlv42/pyramid that referenced this issue Mar 6, 2012
@mcdonc mcdonc closed this as completed in 4a6f532 Mar 12, 2012
@mcdonc
Copy link
Member

mcdonc commented Mar 12, 2012

Thanks a lot!

rbu pushed a commit to rbu/pyramid that referenced this issue Mar 3, 2014
  it possible for instance methods to be used as view callables) introduced a
  backwards incompatibility when methods that declared only a request
  argument were used.  See Pylons#503

Fixes Pylons#503
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

No branches or pull requests

2 participants