Migrating to v4#

Prerequisite#

You have read the ChangeLog of CubicWeb 4.

You already upgraded your CubicWeb application to CubicWeb 3.38, which means you may or not have changed all your import from cubicweb.web to cubicweb_web and installed cubicweb-web package, according to 3.38 changelog. In this version we removed import proxying to cubicweb_web. This means that you can no longer import cubicweb.web. As described in 3.38 changelog, there is a script here https://forge.extranet.logilab.fr/cubicweb/cw_versions_migration_tools made to ease this migration.

Breaking changes and how to keep your application working#

  • AutomaticWebTest, how_many_dict and AutoPopulateTest have been moved from cubicweb.devtools.testlib to cubicweb_web.devtools.testlib.

  • cubicweb.pyramid.bwcompat module have been moved to cubicweb_web.

  • Configuration classes have been simplified:
    • cubicweb.server.serverconfig.ServerConfiguration have been merged into

    cubicweb.cw_config.CubicWebConfiguration, you have to use this one instead of ServerConfiguration - all methods and options from cubicweb.devtools.TestServerConfiguration, and cubicweb.devtools.apptest_config.BaseApptestConfiguration are now in the class cubicweb.devtools.apptest_config.ApptestConfiguration - CubicWeb configuration classes no longer include anything related to the cubicweb_web package.

  • All methods, attributes and properties related to CubicWeb-Web in cubicweb.devtools.testlib.CubicWebTC class have been moved into the class cubicweb_web.devtools.testlib.WebCWTC, which is now the base class for all CubicWeb-Web related tests (if you need Pyramid and CubicWeb-Web, you’ll have to use cubicweb_web.devtools.testlib.PyramidWebCWTC).

  • cubicweb.devtools.fake.FakeRequest have been moved to cubicweb_web.devtools.testlib.

  • cubicweb.ext.rest have been moved to cubicweb_web.ext.rest, thus cubicweb.devtools.apptest_config.ApptestConfiguration no llonger initialize rest components.

  • cubicweb.predicates.paginated_rset have been moved to cubicweb_web.predicates.paginated_rset.

  • cubicweb.pyramid.url_redirections have been moved to cubicweb_web.pyramid.url_redirection, thus, add_redirection_rule pyramid directive is no longer usable without cubicweb_web.

  • cubicweb.utils.HTMLHead and cubicweb.utils.HTMLStream have been moved to cubicweb_web.utils.

  • has_cw_permission pyramid view and route predicates are now in cubicweb_web.pyramid.predicates

  • cubicweb.rset.limited_rql ResultSet method is now a function which can be called from cubicweb_web.views.navigation.limited_rql.

  • cubicweb.web.webconfig.WebConfiguration have been moved to cubicweb_web.webconfig.

  • cubicweb.devtools.RealDatabaseConfiguration have been removed. You can redo it yourself by heriting from cubicweb.devtools.apptest_config.ApptestConfiguration and adding the following class attributes: skip_db_create_and_restore = True and read_instance_schema = True.

  • by default, there is no more session added to the pyramid request. Thus, you cannot access request.session anymore if you don’t use pyramid_session_redis or if you don’t include cubicweb.pyramid.session in pyramid.ini (see below).

  • cubicweb.pyramid.auth is no longer included by default in pyramid config, you will need to add it manually in pyramid.ini (see below)

  • Since cubicweb.pyramid.session and cubicweb.pyramid.auth are now included only in pyramid.ini, you may need to add them manually in your test, in settings class attribute of cubicweb_web.devtools.testlib.PyramidWebCWTC. For instance: settings = {"cubicweb.includes": ["cubicweb.pyramid.auth", "cubicweb.pyramid.session"]}.

  • Now, all modules in the cubicweb.includes directives in the pyramid.ini file are included before all cubes’ include directives.

Pyramid configuration file: pyramid.ini#

  • cubicweb.defaults option has been removed from explicit inclusions. Previously, cubicweb.defaults added 3 modules: cubicweb.pyramid.login, cubicweb.pyramid.auth and cubicweb.pyramid.session. cubicweb.pyramid.login is now in CubicWeb-Web; cubicweb.pyramid.auth and cubicweb.pyramid.session need to be included in cubicweb.includes directive. By default, cubicweb.pyramid.session is commented, thus there is no infinite CWSession objects created in your database if you forget to use an other session storage in production. This also means you can no longer use request.session.

  • Two other module are included by default in pyramid.ini when you create your instance: cubicweb.pyramid.rest_api.include_html and cubicweb.pyramid.rest_api.include_rdf. They add respectively default RDF views and default HTML views in order to describe entities.

  • If you create a new instance, you will have a better pyramid.ini from our new upgraded template. In order to migrate an old instance, you may want to take a look at the template here

  • As before, all directive in pyramid.ini can be added in tests using settings class attribute of cubicweb_web.devtools.testlib.PyramidWebCWTC. For instance: settings = {"cubicweb.includes": ["cubicweb.pyramid.auth", "cubicweb.pyramid.session"]}.

Content negociation#

CubicWeb 4 keep by default a mecanism allowing to have entities description in html or in RDF. They can be disabled or enabled in pyramid.ini configuration file.

CubicWebRequest#

There is no longer CubicWebRequest inside Pyramid Request (except if you add cubicweb-web cube). However, there is still a cubicweb connection accessible by request.cw_cnx, which can be used for many purpose, for instance execute RQL queries.