A new explicit Connection object replaces Session as the main repository entry point. A Connection holds all the necessary methods to be used server-side (execute, commit, rollback, call_service, entity_from_eid, etc...). One obtains a new Connection object using session.new_cnx(). Connection objects need to have an explicit begin and end. Use them as a context manager to never miss an end:
with session.new_cnx() as cnx: cnx.execute('INSERT Elephant E, E name "Babar"') cnx.commit() cnx.execute('INSERT Elephant E, E name "Celeste"') cnx.commit() # Once you get out of the "with" clause, the connection is closed.
Using the same Connection object in multiple threads will give you access to the same Transaction. However, Connection objects are not thread safe (hence at your own risks).
repository.internal_session is deprecated in favor of repository.internal_cnx. Note that internal connections are now safe by default, i.e. the integrity hooks are enabled.
Backward compatibility is preserved on Session.
A new API has been introduced to replace the dbapi. It is called repoapi.
There are three relevant functions for now:
On the client/web side, the Request is now using a repoapi.ClientConnection instead of a dbapi.Connection. The ClientConnection has multiple backward compatible methods to make it look like a dbapi.Cursor and dbapi.Connection.
Sessions used on the Web side are now the same as the ones used Server side. Some backward compatibility methods have been installed on the server side Session to ease the transition.
The authentication stack has been altered to use the repoapi instead of the dbapi. Cubes adding new elements to this stack are likely to break.
All current methods and attributes used to access the repo on CubicWebTC are deprecated. You may now use a RepoAccess object. A RepoAccess object is linked to a new Session for a specified user. It is able to create Connection, ClientConnection and web side requests linked to this session:
access = self.new_access('babar') # create a new RepoAccess for user babar with access.repo_cnx() as cnx: # some work with server side cnx cnx.execute(...) cnx.commit() cnx.execute(...) cnx.commit() with access.client_cnx() as cnx: # some work with client side cnx cnx.execute(...) cnx.commit() with access.web_request(elephant='babar') as req: # some work with web request elephant_name = req.form['elephant'] req.execute(...) req.cnx.commit()
By default testcase.admin_access contains a RepoAccess object for the default admin session.