Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

Re: Module loading priority and inheritance

by
DEC, Yann Papouin
- 17/06/2022 10:59:47
After investigation, the sequence field is only used for the kanban view to display applications in a specific order.

Module list is fetched from database in odoo/odoo/modules/loading.py::load_marked_modules with this query

cr.execute("SELECT name from ir_module_module WHERE state IN %s" ,(tuple(states),))

So, the module loading order actually depends on 4 params:
  1. PostgreSQL database collation
  2. Module name
  3. Datetime of the creation of the ir_module_module row (since no ORDER BY is defined in the query)
  4. The dependencies
That's a terrible loading implementation as the parameter 3 is based on an internal postgreSQL data, it also depends on the list order of your addons_path and also depends on when odoo/addons/base/models/ir_module.py::update_list is called.

Example for this last assertion:
  • On the development database:
    • You add the module account_extra, that depends on account and override method update_something, in your main addons path
    • update_list()
    • Two weeks later, you add the module account_best , that also depends on account and also override the method update_something, in your main addons path
    • update_list()
    • Module account_extra will be loaded before account_best
  • Three weeks later, on the production database:
    • You add modules account_extra and account_best in your main addons path
    • update_list()
    • Module account_best will be loaded before account_extra
And there I'm not talking about other cases like:
  • Multiple addons_path
  • Manual module deletion from odoo module list followed by a module list update
  • Manual module installation from UI whereas the server is already started with loaded modules

So, I agree that most cases would be solved by the depends attribute but a fix could still be:
  • Add a loading_priority manifest key:
    • default value is 0 if not set, could be positive (load before) or negative (load after)
    • add an ORDER BY loading_priority, name in all SQL query of the loading.py
  • Add a soft_depends manifest key:
    • a list of modules that we depends on, only if they exists and are installed

Reference