How to safely upgrade Odoo addons
In this short blog post, i will try to explain how to safely upgrade custom addons on Odoo instance.
Why this question arises? Usualy, in cases of small changes in addons, it is enough to restart Odoo server and possibly to update chaned addon via UI. But, when changes are more complex and touches larger set of addons, then we have to be careful, to apply such updates in right way.
Always backup before update. I think it is good idea to always do backup before update, especially in case of big updates.
Environment. This post is applicable for installation on premises on linux operation systems. Odoo.SH has its own upgrade mechanism, that we cannot change, so it is not covered by this post.
Basic rules for safe upgrade
Following operations will help to prepare to safe upgrade
Backup your database(s)
Always do backup of database (or databases) before update. Backup will help you to easly restore your operations in case of any troubles with backup
Stop the server
Theoretically, it is possible to update Odoo without downtime, but in case if you wnat to upgrade safely, it is better to stop server before upgrade starts.
Update custom addons folder
It is common mistake, to update only single addon on server, which leads to errors, when you forget to add dependency, or to update dependency of this addon.
Install missing system depdendencies
Some addon requires external system dependencies to be installed to make them work. For this case we have to check if all of them installed and available for Odoo.
Steps to upgrade safely
Update python requirements for each addon
In some cases, new python dependencies may be added to odoo addon to implement new feature. So, we have to ensure that all python requirements installed.
Update list of addons in each database on server
In case of new dependencies been added, we have to make odoo to find them.
Also, update list of addos for each database on server
Update addons via CLI for each database on server
The preferred way to update addons is to use CLI, becuase some changes my cause web UI not to work. Also, we always have to run update for all databases on server
Start the server
Start the odoo server and check if everything is working.
Please, do not forget to check if after server started it is accesible via web UI.
Step by step guide for upgrade
So, lets walk through step-by-step guide for update of Odoo
Do backup. Just follow this simple rule. Realy, why so many people are too lazy to do backup? Just follow this simple rule, and it allows you to avoid a lot af troubles.
Stop the server. Usualy, update contains changed to python code, and models. If we do not stop the server, we will have odoo processes that are running with old version of code and old database structure. Also, if we have running server available for external users, then we have a great chance to get update failure because of concurency errors, or any other unexpected errors. So, it is better to stop the server and continue update process in safe.
Update custom addons folder. This is one of the most important steps to have safe upgrade. Usualy, there is one or maybe few folders (directories) for custom addons on the server. These folders may be controlled with git (the safe way), or just contain set of downloaded addons. And, the one thing, that users forget to do, is to remove old version of addon, before copying new version. This way leads, to that old files are present in addon, that me cause some strange errors. Also, you have to ensure that all addons in this folder has correct versions, before going to next step. Especialy in case of third party addons.
Install missing dependencies. Some times, new version of addon may require system dependency to work. So, before applying update, it is better to review changes, and install missing system dependencies. Git could help a lot in this case, because it allows you to see changes that have to be applied. Usualy, external (system) dependencies specified in manifest file of addon, or in readme, so, you can check what was changed in this files, before applying update.
Update python requirements. In some cases, new versions of addon require some additional python packages, or require newer version of python package. Thus we have to ensure that we have installed all required python packages. Usualy, if addon requires python dependencies, it has requirements.txt file inside the addons folder. This file contains list of python dependencies. So, we have to install python dependencies via pip via command like following: sudo pip install -r path_to_custom_addons_dir/addon_name/requirements.txt.
Update list of addons. Because, update may introduce new addons, we have to update list of addons in each database on the server. This step is required if changed addons introduce new dependencies. Also, instead of updating list of addons, it is possible to update base module, but it leads to logner update duration. You can use odoo shell to run python code in odoo environment (odoo shell -d dbname -c path_to_config_file --no-http) and then you can use following python code to update list of addons: env['ir.module.module'].update_list(); env.cr.commit(); Also, do not forget to apply this to all databases on server.
Update addons. On this step we can start actual update of addons. It is required to run update via CLI when update changes res.partner or res.users models, because in this case web interface may not work. One more requirement is to update all changed addons (or all addons in repository) with single command. This is required, because in this case, odoo will automatically resolve dependencies, and do update in correct order, so doing update in this way allows you to avoid a lot of errors during update. Also, it is required to run update for all database of server, even if you think that changed addons was not installed on that databases. This is required, becuase some addons has auto_install options, thus the could be installed on that databases automatically.
You can run update of mutiple addons using following command:
odoo -c path_to_odoo_config_file -d database_name --no-http --stop-after-init --update=addon1,addon2,addon3,addonN
Start the server. Do not forget to start server and manualy check that it works after upgrade.
This post describes general rules for update, concreet commands and process of update depends on your configuration and the way you deploy odoo. Anyway, i hope that this post was helpful for you.
If you have any suggestions to improve this post, then just send mail to firstname.lastname@example.org.