[Cubicweb] PYRAMID: Integrated sessions & error management (a.k.a. getting rid of 'appli')

Christophe de Vienne christophe at unlish.com
Tue Jul 15 19:18:56 CEST 2014


Hi all,

Today Aurélien and I worked on pyramid_cubicweb.

The goals were to:
1) clarify the session management.
2) skip CubicWebPublisher.core_handle, if not CubicWebPublisher altogether.

You can find the result of our work in the new pyramid_cubicweb 
repository at http://hg.logilab.org/review/pyramid_cubicweb


1) Session Management

The chosen approach is to let pyramid entirely handle sessions and 
session datas.
Because CubicWeb still rely on a "repository session" object, we get a 
new one for each request, and its ".data" attribute is replaced by the 
pyramid session object.
At the end of the request handling by pyramid, the cubicweb session 
object is closed.

This way we have something very compatible for the current cubicweb 
applications that totally rely on pyramid for session handling.

2) CubicWebPublisher

core_handle is a big function that:
- use the url resolver to build a rset and obtain a controller id
- select a controller, feed it the request and get a content from it
- handle most of the exceptions that may occur during these two steps

In all the handle errors, a part of them may be raise by any cubicweb 
appobject, including views, that we will call 'external errors' for 
convenience. The other errors should occur only in a resolver of a 
controller, we will call them 'internal errors'.

All there errors have to be translated to their pyramid equivalent.

Since the 'external errors' can be raise by any cubicweb component, they 
also have to be translated when we render a view.

To address all that, we implemented a context manager 
(cw_to_pyramid(request)) that handle all the external errors. It is used 
in render_view as well as in the default handler.

In addition, the default handler now does the resolving + controller 
call directly, and handle the internal errors.

We now rely on CubicWebPublisher only to handle validation errors, and 
that should be easy to change. So we basically got (almost) rid of 
CubicWebPublisher (aka 'application').


For those not used to cubicweb, I will push asap a requirements.txt that 
will make working on pyramid_cubiweb a lot easier than it is now.

Regards,

Christophe



More information about the Cubicweb mailing list