From 292645573bfb8ac06471b2c5de079a9b8b7f0bac Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Mon, 17 Jan 2022 09:45:25 +0000 Subject: [PATCH] [IMP] core: don't save config when setting admin password When setting the password in the database manager the config is saved automatically in a odoorc file. This can be problematic, especially when testing locally, with specific options. Going in the database manager and creating a new database or changing admin pasword will save all those options. This commit proposes to only save the admin_passwd when modified. Part-of: odoo/odoo#82874 --- odoo/service/db.py | 2 +- odoo/tools/config.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/odoo/service/db.py b/odoo/service/db.py index 639379f46f9..f79a2d4e35b 100644 --- a/odoo/service/db.py +++ b/odoo/service/db.py @@ -347,7 +347,7 @@ def exp_rename(old_name, new_name): @check_db_management_enabled def exp_change_admin_password(new_password): odoo.tools.config.set_admin_password(new_password) - odoo.tools.config.save() + odoo.tools.config.save(['admin_passwd']) return True @check_db_management_enabled diff --git a/odoo/tools/config.py b/odoo/tools/config.py index 354e2467d97..74a9416e6f3 100644 --- a/odoo/tools/config.py +++ b/odoo/tools/config.py @@ -633,11 +633,17 @@ class configmanager(object): except ConfigParser.NoSectionError: pass - def save(self): + def save(self, keys=None): p = ConfigParser.RawConfigParser() loglevelnames = dict(zip(self._LOGLEVELS.values(), self._LOGLEVELS)) - p.add_section('options') + rc_exists = os.path.exists(self.rcfile) + if rc_exists and keys: + p.read([self.rcfile]) + if not p.has_section('options'): + p.add_section('options') for opt in sorted(self.options): + if keys is not None and opt not in keys: + continue if opt in ('version', 'language', 'translate_out', 'translate_in', 'overwrite_existing_translations', 'init', 'update'): continue if opt in self.blacklist_for_save: @@ -656,7 +662,6 @@ class configmanager(object): # try to create the directories and write the file try: - rc_exists = os.path.exists(self.rcfile) if not rc_exists and not os.path.exists(os.path.dirname(self.rcfile)): os.makedirs(os.path.dirname(self.rcfile)) try: