On Nov 15, 4:54 pm, Gustavo Narea <[email protected]> wrote:
> The only thing I can think of is that the repoze.who middleware was
> added in the wrong order. Please have a look at this
> example:https://bitbucket.org/Gustavo/whatpylonsproject/src/tip/pylonssecured...
>
> I don't remember seeing that error before. Can you please paste the
> traceback if the location of the middleware is not the problem?
Thanks for the reply.
My middleware.py looks very similar to the one you linked. The middle
is slightly different (I haven't done anything with caching, and I
added ToscaWidgets; neither looks like it should be a problem):
# Routing/Session/Cache Middleware
app = RoutesMiddleware(app, config['routes.map'], singleton=False)
app = SessionMiddleware(app, config)
# CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
app = twa.make_middleware(app, {
'toscawidgets.framework': 'pylons',
'toscawidgets.framework.default_view': 'mako',
})
app = add_auth(app)
if asbool(full_stack):
# Handle Python exceptions
app = ErrorHandler(app, global_conf,
**config['pylons.errorware'])
My add_auth uses repoze.what.plugins.quickstart.setup_sql_auth, like
the one you linked. (Actually, I think I followed your cookbook
article.)
I posted the traceback to http://pastie.org/1301390.
After investigating a bit more, here's my understanding of the
problem. Please correct me if I'm wrong:
As described at
http://www.sqlalchemy.org/trac/wiki/FAQ#Thetransactionisinactiveduetoarollbackinasubtransaction,
uses of Session should make sure that they end with a call to
rollback(), close(), or remove(). Pylons does this in its
BaseController, but because repoze.who.plugins.sa is configured as
middleware, it executes outside of BaseController's try/finally block,
so any errors it encounters are never rolled back.
I can think of three solutions:
1) Give repoze.what.quickstart a Session object with autocommit=True,
so that it never has to rollback. I guess this would mean creating
two session objects (one for Pylons with autocommit=False, one for
repoze.who / repoze.what with autocommit=True); are there any caveats
with doing this?
2) Initialize and close the Session within middleware rather than
within the Pylons app (something like
http://pypi.python.org/pypi/SQLAlchemyManager/0.1.0?).
3) Add try/except blocks to repoze.who.plugins.sa.
#3 seems like the correct solution, but I'm very new to Pylons,
repoze, SQLAlchemy, and WSGI middleware, so I could easily be
misunderstanding something.
--
Josh Kelley
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.