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_dictandAutoPopulateTesthave been moved fromcubicweb.devtools.testlibtocubicweb_web.devtools.testlib.cubicweb.pyramid.bwcompatmodule have been moved tocubicweb_web.cubicweb.sobjects.notification.RecipientFinderis no more acomponent, but aservice. Thus, this class and all its potential children are now inservicesregistry instead ofcomponentsregistry.- Configuration classes have been simplified:
cubicweb.server.serverconfig.ServerConfigurationhave been merged intocubicweb.cw_config.CubicWebConfiguration, you have to use this one instead ofServerConfigurationall methods and options from
cubicweb.devtools.TestServerConfiguration, andcubicweb.devtools.apptest_config.BaseApptestConfigurationare now in the classcubicweb.devtools.apptest_config.ApptestConfigurationCubicWeb configuration classes no longer include anything related to the
cubicweb_webpackage.
All methods, attributes and properties related to CubicWeb-Web in
cubicweb.devtools.testlib.CubicWebTCclass have been moved into the classcubicweb_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 usecubicweb_web.devtools.testlib.PyramidWebCWTC).cubicweb.devtools.fake.FakeRequesthave been moved tocubicweb_web.devtools.testlib.cubicweb.ext.resthave been moved tocubicweb_web.ext.rest, thuscubicweb.devtools.apptest_config.ApptestConfigurationno longer initialize rest components.cubicweb.predicates.paginated_rsethave been moved tocubicweb_web.predicates.paginated_rset.cubicweb.pyramid.url_redirectionshave been moved tocubicweb_web.pyramid.url_redirection, thus,add_redirection_rulepyramid directive is no longer usable withoutcubicweb_web.cubicweb.utils.HTMLHeadandcubicweb.utils.HTMLStreamhave been moved tocubicweb_web.utils.has_cw_permissionpyramid view and route predicates are now incubicweb_web.pyramid.predicatescubicweb.rset.limited_rqlResultSetmethod is now a function which can be called fromcubicweb_web.views.navigation.limited_rqland_limit_offset_rqlResultSetmethod is now a function which can be called fromcubicweb_web.views.navigation._limit_offset_rql.cubicweb.web.webconfig.WebConfigurationhave been moved tocubicweb_web.webconfig.cubicweb.devtools.RealDatabaseConfigurationhave been removed. You can redo it yourself by heriting fromcubicweb.devtools.apptest_config.ApptestConfigurationand adding the following class attributes:skip_db_create_and_restore = Trueandread_instance_schema = True.by default, there is no more session added to the pyramid request. Thus, you cannot access
request.sessionanymore if you donât use pyramid_session_redis or if you donât includecubicweb.pyramid.sessionin pyramid.ini (see below).cubicweb.pyramid.authis no longer included by default in pyramid config, you will need to add it manually in pyramid.ini (see below)Since
cubicweb.pyramid.sessionandcubicweb.pyramid.authare now included only in pyramid.ini, you may need to add them manually in your test, insettingsclass attribute ofcubicweb_web.devtools.testlib.PyramidWebCWTC. For instance:settings = {"cubicweb.includes": ["cubicweb.pyramid.auth", "cubicweb.pyramid.session"]}.Now, all modules in the
cubicweb.includesdirectives in the pyramid.ini file are included before all cubesâincludedirectives.
Pyramid configuration file: pyramid.ini#
cubicweb.defaultsoption has been removed from explicit inclusions. Previously,cubicweb.defaultsadded 3 modules:cubicweb.pyramid.login,cubicweb.pyramid.authandcubicweb.pyramid.session.cubicweb.pyramid.loginis now in CubicWeb-Web;cubicweb.pyramid.authandcubicweb.pyramid.sessionneed to be included incubicweb.includesdirective. By default,cubicweb.pyramid.sessionis 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 userequest.session.Two other module are included by default in pyramid.ini when you create your instance:
cubicweb.pyramid.rest_api.include_htmlandcubicweb.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
settingsclass attribute ofcubicweb_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.
Translations#
A lot of translations were generated for cubicweb.web views and components. These
translations had been moved to cubicweb-web cube, and its generations too.
In order to still have it, you will need to add a cubicweb.i18ncube entrypoint to your package:
"cubicweb.i18ncube": [
"<your cube name>=cubicweb_web.i18n:WebI18nCubeMessageExtractor",
]
With <your cube name> being the name of your cube.