RFC: replacement of server_environment
Authors:
Issues with server_environment we would like to fix
-
Reduce maintenance work: no more glue modules for every little field to be configured through env
-
Allow non-technical people to easily configure things directly in Odoo UI (e.g: test new mail server, sftp, etc)
-
Drop the hacky conversion to computed fields
Explored alternatives
- Replacement with a module that encrypts fields directly in db
Too complicated. Even more complicated than the current solution.
- Explore alternative without computed fields, like fetch
Still hacky and still requires lots of maintenance.
- Replacement with an SQL-based entrypoint
Chosen solution. Described below.
Proposed solution
Inspired by the neutralize command, that executes raw SQL queries to clear credentials out from the database, we propose building a command line tool that writes environment-specific field values directly to the db. Essentially, this means preparing the database for the environment that’s gonna run on, and letting Odoo work on its own without any hacks.
The tool will only overwrite the credentials in the spec, but it will not worry about clearing them out. For that, we will rely directly on the neutralize command and we will encourage developers to include neutralization scripts on the modules that require them.
The idea is then to:
-
Configure production environments directly from the UI and stored in the db – purely standard, no added magic
-
Rely on the neutralization script to clear them out when restoring a db to a non-production environment.
-
Use the new tool to transform an input file/content set through the environment to SQL-queries, and set the environment-specific settings/credentials
This will be used to, for example, connect to a test sftp server instead. It will not be needed if we don’t want the test instance to connect to a specific server, though, as we will rely on neutralize to have it disabled anyway.
Packaging
This will be an external tool, not an Odoo module, that will work across Odoo versions.
Supported Odoo Versions
It must support Odoo >= 16.0, which is when neutralize was implemented.
The tool itself could be used to neutralize a list of model/fields by setting them to a falsy value, and so support previous versions too.
Input
The tool input will be a spec that defines the records and fields values to overwrite.
Originally we wanted to support a syntax similar to the one in the existing server_environment module: the ini format configuration files, using sections for model-wide settings and dotted notation for record-specific settings.
However, the global section name and the name field for record specific settings (tech_name) are defined in the module itself, and this would pose challenges for an implementation where this module is uninstalled, and so this information is missing.
Additionally, we may want to support smarter ways of targeting records, like with XML-ids or raw model names → we need a syntax that doesn’t require modifying the models’ schema
We will stick to ini format since it matches odoo.conf.
Examples:
# Model-wide settings (all records of this model)
# Section Syntax: [model:model_name]
[model:ir.mail_server]
smtp_port = 22
smtp_user = username
# Record settings using xml-id
# Section Syntax: [record:xml_id]
[record:customer_module.sftp_server]
sftp_port = 9999
sftp_user = username
# Additionally, config parameters can be set with
[config:set_param]
param.key = value1
another.parameter = value2
Note: camptocamp currently uses model-wide settings mainly in the following cases:
- outgoing_mail: setting mailpit everywhere
- incoming_mail: setting mailtrap everywhere
- printing server
- sometimes singleton backend records: can be migrated to xmlid
Output
The tool will transform each configuration section and value to raw SQL queries and execute them
Note: A pure SQL solution may be able to guess table and column names and work well in most cases, but it will fail to handle models with a custom _table (e.g.: ir.actions.actions → ir_actions instead of ir_actions_actions)
We may want to actually run the ORM for more accurate processing, though
Execution
For non-production environments, it must be executed after neutralize has ran, because we want our settings to not be cleared by it.
The way to run the script will probably depend on the way Odoo is deployed on your instances. We have some ideas about how to manage this in our deployments, but of course we welcome feedback for documenting a process that is streamlined with other's deployment usage.
Configuration
The production database must have all settings directly configured. No environment-specific settings.
All modules must have proper neutralization scripts. Check OCA and specific modules, trust Odoo to handle core modules.
The test environment databases will have production settings automatically cleared by neutralize, but will require environment-specific settings for things we want to persist.
Migration path from server_environment
Originally we wanted the transition to be effortless, by supporting the exact same syntax as server_environment.
However, this won’t be possible because some important information will be lost as soon as server_environment is uninstalled:
- The record’s tech_name, often used as IDs in the server env settings
*The model’s “section name” and “global section name”, also used to map settings to records
Nonetheless, the transition can be done manually and gradually, by supporting both modules to co-exist.
We are also thinking about trying to manage things in an uninstall hook. Something will be needed anyway because we need to get the columns back on the models for which some fields are no longer managed through server environment.
Next steps
RFC: replacement of
server_environmentAuthors:
Issues with server_environment we would like to fix
Reduce maintenance work: no more glue modules for every little field to be configured through env
Allow non-technical people to easily configure things directly in Odoo UI (e.g: test new mail server, sftp, etc)
Drop the hacky conversion to computed fields
It breaks the CLI neutralize queries (used in our platform and in Odoo.sh)
It can break core bussiness logic due to computed fields behaving differently
Explored alternatives
Too complicated. Even more complicated than the current solution.
Still hacky and still requires lots of maintenance.
Chosen solution. Described below.
Proposed solution
Inspired by the neutralize command, that executes raw SQL queries to clear credentials out from the database, we propose building a command line tool that writes environment-specific field values directly to the db. Essentially, this means preparing the database for the environment that’s gonna run on, and letting Odoo work on its own without any hacks.
The tool will only overwrite the credentials in the spec, but it will not worry about clearing them out. For that, we will rely directly on the neutralize command and we will encourage developers to include neutralization scripts on the modules that require them.
The idea is then to:
Configure production environments directly from the UI and stored in the db – purely standard, no added magic
Rely on the neutralization script to clear them out when restoring a db to a non-production environment.
Use the new tool to transform an input file/content set through the environment to SQL-queries, and set the environment-specific settings/credentials
This will be used to, for example, connect to a test sftp server instead. It will not be needed if we don’t want the test instance to connect to a specific server, though, as we will rely on neutralize to have it disabled anyway.
Packaging
This will be an external tool, not an Odoo module, that will work across Odoo versions.
Supported Odoo Versions
It must support Odoo >= 16.0, which is when neutralize was implemented.
Input
The tool input will be a spec that defines the records and fields values to overwrite.
Originally we wanted to support a syntax similar to the one in the existing
server_environmentmodule: the ini format configuration files, using sections for model-wide settings and dotted notation for record-specific settings.However, the global section name and the name field for record specific settings (tech_name) are defined in the module itself, and this would pose challenges for an implementation where this module is uninstalled, and so this information is missing.
Additionally, we may want to support smarter ways of targeting records, like with XML-ids or raw model names → we need a syntax that doesn’t require modifying the models’ schema
We will stick to ini format since it matches
odoo.conf.Examples:
Note: camptocamp currently uses model-wide settings mainly in the following cases:
Output
The tool will transform each configuration section and value to raw SQL queries and execute them
Note: A pure SQL solution may be able to guess table and column names and work well in most cases, but it will fail to handle models with a custom _table (e.g.: ir.actions.actions → ir_actions instead of ir_actions_actions)
We may want to actually run the ORM for more accurate processing, though
Execution
For non-production environments, it must be executed after neutralize has ran, because we want our settings to not be cleared by it.
The way to run the script will probably depend on the way Odoo is deployed on your instances. We have some ideas about how to manage this in our deployments, but of course we welcome feedback for documenting a process that is streamlined with other's deployment usage.
Configuration
The production database must have all settings directly configured. No environment-specific settings.
All modules must have proper neutralization scripts. Check OCA and specific modules, trust Odoo to handle core modules.
The test environment databases will have production settings automatically cleared by neutralize, but will require environment-specific settings for things we want to persist.
Migration path from
server_environmentOriginally we wanted the transition to be effortless, by supporting the exact same syntax as
server_environment.However, this won’t be possible because some important information will be lost as soon as
server_environmentis uninstalled:*The model’s “section name” and “global section name”, also used to map settings to records
Nonetheless, the transition can be done manually and gradually, by supporting both modules to co-exist.
We are also thinking about trying to manage things in an uninstall hook. Something will be needed anyway because we need to get the columns back on the models for which some fields are no longer managed through server environment.
Next steps