Skip to content

ERP5Site,component_package: call createFilesystemImportDict from ERP5ite.__init__

Jérome Perrin requested to merge fix/create_fs_import_dict__of__ into master

The previous approach of calling it from the Loader has an issue that it needs a site to be active, otherwise we could see errors like this:

  Traceback (most recent call last):
    File "./bin/runUnitTest", line 363, in <module>
      import Products.ERP5Type.tests.coverage_report
    File "./parts/erp5/product/ERP5Type/dynamic/component_package.py", line 358, in find_module
      erp5.component.createFilesystemImportDict()
    File "./parts/erp5/product/ERP5Type/dynamic/component_package.py", line 189, in createFilesystemImportDict
      component_tool = aq_base(getSite().portal_components)
    File "./parts/erp5/product/ERP5/ERP5Site.py", line 273, in __get
      app, site_id = self.site[-1]
  IndexError: list index out of range

This specific error happened on https://erp5js.nexedi.net/#/test_result_module/20260605-4888DCEB/390 at the end of the test. In most cases, find_module has a site active, but because site is managed with a weakref, if the garbage collection happened, the site is no longer active and it's not possible to import Products.

Instead of having createFilesystemImportDict in component_package, which works only if getSite works (ie. during a zope request or soon enough after a request when the weakref was not gc'd), populate the import dict during ERP5Site.__of__, when we for sure have a site available.

Merge request reports