Skip to content
This repository

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

Closed
hlv42 opened this Issue March 05, 2012 · 1 comment

2 participants

hlv42 Chris McDonough
hlv42
hlv42 commented March 05, 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 hlv42 referenced this issue from a commit in hlv42/pyramid March 06, 2012
fixed issue #461
- 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.
719a379
hlv42 hlv42 referenced this issue from a commit in hlv42/pyramid March 06, 2012
hlv42 corrected bugfix #461 - tests explicitly for instancemethods now
testcase added
df3bea9
Chris McDonough mcdonc closed this in 4a6f532 March 11, 2012
Chris McDonough
Owner

Thanks a lot!

Michael Merickel mmerickel referenced this issue in bbangert/velruse August 02, 2012
Closed

Login breaks with Pyramid 1.2 #82

Robert Buchholz rbu referenced this issue from a commit in rbu/pyramid March 20, 2012
Chris McDonough - The fix for issue Pylons#461 (which made
  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 #503
6c15971
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.