[Cubicweb] Understanding _cw

Aurélien Campéas aurelien.campeas at logilab.fr
Wed May 14 18:08:36 CEST 2014


Hello,

The mysterious _cw object has always bothered my, because
it can be different things in the same places in different
contexts.

For instance, in CubicWeb 3.18, _cw can be either a Session
object or a CubicWebTwistedRequestAdapter object (AFAIK).

"_cw" is used in views, entities and hooks.

I tried to compute the precise interface of _cw in 3.19, and
here's the method list I got:

>>> cubicwebrequestbase.intersection(clientconnection)
set(['execute', 'describe', 'drop_entity_cache', 'entity_metas',
'call_service', 'set_entity_cache', 'cached_entities', 'source_defs',
'entity_cache'])

(ClientConnection replaces Session in 3.19 for most purposes)

Also hooks have this too.

Is it reasonnable ?

In practice, I've learnt to organize my application code to deal with
this, but it hurts.

Then, there is ClientConnection (from repoapi.py) vs Connection (from
session.py).

>>> connection.intersection(clientconnection)
set(['security_enabled', 'execute', 'rollback', 'drop_entity_cache',
'entity_metas', 'call_service', 'deny_all_hooks_but',
'cached_entities', 'allow_all_hooks_but', 'set_entity_cache',
'system_sql', 'commit', 'source_defs', 'entity_cache'])

So I feel like we could separate a bit more concerns and provide
*explicit* interfaces. Especially, the _cw object should be clearly
documented.

This is only food for thought and the start of an investigation ...

Regards,
Aurélien




More information about the Cubicweb mailing list