cubicweb #1534590 Keep references on cnx to avoid closing sessions [deprecated]
In a little script, I've used the following code: def get_repo_session(): from cubicweb.dbapi import in_memory_cnx from cubicweb.etwist.twconfig import AllInOneConfiguration config = AllInOneConfiguration('mycube') repo, cnx = in_memory_cnx(config, login='xxx', password='xxx') session = repo._get_session(cnx.sessionid) return session session = get_repo_session() session.execute('...') # and so on and have been bitten by an AttributeError : Session has no _tx_data attribute. The reason here is that cnx (from get_repo_session() no longer being referenced, cnx.__del__ is called and session is closed. One easy solution would be for session to keep a reference to corresponding cnx. | |
priority | normal |
---|---|
type | bug |
done in | <not specified> |
load | 0.000 |
load left | 0.000 |
closed by | <not specified> |
similar entities
- cubicweb #1568456 login parameter should be mandatory for cubicweb.dpapi.connect
- cubicweb #2099892 Improve transaction_data API
- cubicweb #1216325 [registry] some events give a self, others do not
- cubicweb #2912807 clarification of various persistent data
- cubicweb #2164478 Flexible sessions handling
[see all]
Comments
-
2011/03/09 08:03, written by adimascio
-
2011/03/09 08:36, written by sthenault
add commentActually, it might simply be that this way of doing is wrong but ... each time I look at cubicweb.dbapi, my feeling is that there are too many ways of doing things similar (actually really-close-but-not-really-similar) : repo_connect, in_memory_cnx, connect. Then I never really know which way is supposed to be the way.
we probably want one function to get a dbapi connection (`connect`), and
another to get an in-memory session as public entry point.