FormAlchemy / pyramid_formalchemy

44 stars 14 forks source link

`resources.Base.get_instance` returns an `i18n.I18NModel`. #19

Closed thruflo closed 11 years ago

thruflo commented 12 years ago

Hi,

I get the following error trying to view a model I've created through fa.bootstrap's pyramid_formalchemy UI. request.model_class is an i18n.I18NModel instance, which causes get_instance to bork, as it should be trying to query the i18n.I18NModel instance's context.

Thanks,

James.

Traceback (most recent call last):
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid_debugtoolbar-0.9.8-py2.6.egg/pyramid_debugtoolbar/toolbar.py", line 115, in toolbar_tween
    response = _handler(request)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid_debugtoolbar-0.9.8-py2.6.egg/pyramid_debugtoolbar/panels/performance.py", line 55, in resource_timer_handler
    result = handler(request)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid-1.3a6-py2.6.egg/pyramid/tweens.py", line 20, in excview_tween
    response = handler(request)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid_tm-0.3-py2.6.egg/pyramid_tm/__init__.py", line 61, in tm_tween
    response = handler(request)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid-1.3a6-py2.6.egg/pyramid/router.py", line 164, in handle_request
    response = view_callable(context, request)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid-1.3a6-py2.6.egg/pyramid/config/views.py", line 564, in __call__
    return view(context, request)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid-1.3a6-py2.6.egg/pyramid/config/views.py", line 290, in attr_view
    return view(context, request)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid-1.3a6-py2.6.egg/pyramid/config/views.py", line 263, in predicate_wrapper
    return view(context, request)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid-1.3a6-py2.6.egg/pyramid/config/views.py", line 316, in rendered_view
    result = view(context, request)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid-1.3a6-py2.6.egg/pyramid/config/views.py", line 416, in _class_view
    response = getattr(inst, attr)()
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid_formalchemy-0.4.3-py2.6.egg/pyramid_formalchemy/actions.py", line 77, in wrapped
    return func(self, *args, **kwargs)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid_formalchemy-0.4.3-py2.6.egg/pyramid_formalchemy/views.py", line 348, in show
    return self.render(fs=fs, id=id)
  File "/Users/thruflo/Development/sandbox/bootstrap/bootstrap/forms.py", line 19, in render
    result = super(ModelView, self).render(**kwargs)
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid_formalchemy-0.4.3-py2.6.egg/pyramid_formalchemy/views.py", line 175, in render
    breadcrumb=self.breadcrumb(**kwargs),
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid_formalchemy-0.4.3-py2.6.egg/pyramid_formalchemy/views.py", line 146, in breadcrumb
    items.append((request.fa_url(model_name, id), u'%s' % self.context.get_instance(), 'instance_url'))
  File "/Users/thruflo/Development/sandbox/fa/lib/python2.6/site-packages/pyramid_formalchemy-0.4.3-py2.6.egg/pyramid_formalchemy/resources.py", line 76, in get_instance
    return session.query(model).get(self.request.model_id)
  File "build/bdist.macosx-10.6-universal/egg/sqlalchemy/orm/session.py", line 979, in query
    return self._query_cls(entities, self, **kwargs)
  File "build/bdist.macosx-10.6-universal/egg/sqlalchemy/orm/query.py", line 107, in __init__
    self._set_entities(entities)
  File "build/bdist.macosx-10.6-universal/egg/sqlalchemy/orm/query.py", line 114, in _set_entities
    entity_wrapper(self, ent)
  File "build/bdist.macosx-10.6-universal/egg/sqlalchemy/orm/query.py", line 3117, in __init__
    "expected - got '%r'" % (column, )
InvalidRequestError: SQL expression, column, or mapped entity expected - got '<pyramid_formalchemy.i18n.I18NModel object at 0x1044292d0>'
yaoz commented 12 years ago

change: return session.query(model).get(self.request.model_id) to: return session.query(model.context).get(self.request.model_id)