[hook] notification hooks during db-init
In many cubes, we create "Card" entities in postcreate phase. This seems to lead to the following error while we run test:
___________________________ DefaultTC.test_something ___________________________
Traceback (most recent call last):
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/logilab/common/registry.py", line 900, in __getitem__
return super(RegistryStore, self).__getitem__(name)
KeyError: 'components'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/devtools/testlib.py", line 395, in setUp
self._init_repo()
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/devtools/testlib.py", line 324, in _init_repo
db_handler.build_db_cache(self.test_db_id, self.pre_setup_database)
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/devtools/__init__.py", line 476, in build_db_cache
self.init_test_database()
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/devtools/__init__.py", line 809, in init_test_database
init_config=self.init_config)
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/server/__init__.py", line 295, in init_repository
cnx.commit()
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/server/session.py", line 153, in check_open
return func(cnx, *args, **kwargs)
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/server/session.py", line 769, in commit
operation.handle_event('postcommit_event')
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/server/hook.py", line 755, in handle_event
getattr(self, event)()
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/hooks/notification.py", line 66, in postcommit_event
view.render_and_send(**viewargs)
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/sobjects/notification.py", line 83, in render_and_send
for msg, recipients in self.render_emails(**kwargs):
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/sobjects/notification.py", line 92, in render_emails
recipients = self.recipients()
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/cubicweb/sobjects/notification.py", line 151, in recipients
finder = self._cw.vreg['components'].select(
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/logilab/common/registry.py", line 904, in __getitem__
raise exc
File "/builds/biblissima/mandragore/.tox/py3/lib/python3.7/site-packages/logilab/common/registry.py", line 900, in __getitem__
return super(RegistryStore, self).__getitem__(name)
logilab.common.registry.RegistryNotFound: components
----------------------------- Captured stdout call -----------------------------
-> creating tables
-> inserting default user and default groups.
-> storing the schema in the database
The issue here is that we call a hook which should add a notification view (https://forge.extranet.logilab.fr/cubicweb/cubes/card/-/blob/branch/default/cubicweb_card/hooks.py), while view registries aren't loaded. Before this patch: 4f59a56e6d89, no exception where returned, so tests didn't fail.
In my opinion, we should add a piece of code which disable this hook during initialisation: https://forge.extranet.logilab.fr/cubicweb/cubicweb/-/blob/branch/default/cubicweb/hooks/notification.py#L44