External dependencies in odoo
There is some non-obvious issue with external dependency in modules, which I want to say.
Case
Let you need to use some python lib, which is not available in system by default and should be installed manually.
So you just make import:
And maybe you mention required dependence in module's description. Very simple, right? But…
Issue
The case could crash odoo completely.
This is scenario when it could happen:
- User is not going to use your module with external dependency, but
your module available in Local Modules. E.g. if have a lot of
modules in your git repository and user just makes
git clone
and add path to repo toaddons-path
. - User's system doesn't have required dependency
- Your module has
static/
folder, e.g. to place icon.png file.
Then right after restarting server, user would get error:
Suggestion
Whenever you use external dependency, put your import code in try block
and add external_dependencies
to module's manifest:
It will check dependencies before installing and will not raise ImportError if user doesn't use module.