Conflict when using declarative configuration and subclassing

29 views
Skip to first unread message

yorjo

unread,
Oct 23, 2012, 3:12:45 PM10/23/12
to pylons...@googlegroups.com
Hi,

Don't know if it's something that I should not do or a bug but I notice a weird behavior when using declarative configuration and subclassing.

The code:

#in __init__.py of a tutorial project
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    config = Configurator(settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('view_in_base', '/base')
    config.add_route('fake_view_in_derived1', '/derived1')
    config.add_route('view_in_derived2', '/derived2')
    config.scan()
    return config.make_wsgi_app()


# in views.py
class BaseView(object):
    def __init__(self, request):
        self._request = request

    @view_config(route_name='view_in_base')
    def view_in_base(self):
        pass
    
class DerivedView1(BaseView):    
    def __init__(self, request):
        super(DerivedView, self).__init__(request)

#    @view_config(route_name='fake_view_in_derived1')
#    def fake_view_in_derived1(self):
#        pass

class DerivedView2(DerivedView1):    
    def __init__(self, request):
        super(DerivedView2, self).__init__(request)

    @view_config(route_name='view_in_derived2')
    def view_in_derived2(self):
        pass

If I run proutes development.ini on the project I have the following conflict:

pyramid.exceptions.ConfigurationConflictError: Conflicting configuration actions
  For: ('view', None, '', None, <InterfaceClass pyramid.interfaces.IView>, None, None, None, 'view_in_base', 'view_in_base', False, None, None, None, None)
    Line 15 of file /u/joroy/workspace/new_pyramid/new_pyramid/views.py:
        @view_config(route_name='view_in_base')
    Line 15 of file /u/joroy/workspace/new_pyramid/new_pyramid/views.py:
        @view_config(route_name='view_in_base')

If I uncomment the code in class DerivedView1 to have at least one call to view_config in the intermediate class(DerivedView1) I have no conflict. 

Is this the accepted behavior?

Regards,

Jonathan

FYI: I use pyramid-1.3.4






Reply all
Reply to author
Forward
0 new messages