From 4509bd6f62b5b83923a44cdc290826e727395eea Mon Sep 17 00:00:00 2001 From: Vincent Hatakeyama Date: Mon, 24 Jun 2024 17:28:24 +0200 Subject: [PATCH] [IMP] fs_storage: replace {db_name} in directory_path In multi database mode, there was no way to avoid filename collisions --- fs_storage/models/fs_storage.py | 7 +++++++ fs_storage/readme/USAGE.md | 2 ++ fs_storage/readme/newsfragments/db_name.feature | 1 + 3 files changed, 10 insertions(+) create mode 100644 fs_storage/readme/newsfragments/db_name.feature diff --git a/fs_storage/models/fs_storage.py b/fs_storage/models/fs_storage.py index dd97710e5b..c36e48897c 100644 --- a/fs_storage/models/fs_storage.py +++ b/fs_storage/models/fs_storage.py @@ -182,6 +182,13 @@ def _server_env_fields(self): "eval_options_from_env": {}, } + def _server_env_read_from_config(self, field_name, config_getter): + value = super()._server_env_read_from_config(field_name, config_getter) + # replace {db_name} with the dbname + if field_name == "directory_path": + value = value.format(db_name=self.env.cr.dbname) + return value + def write(self, vals): self.__fs = None self.env.registry.clear_cache() diff --git a/fs_storage/readme/USAGE.md b/fs_storage/readme/USAGE.md index ac73b9bc4b..e6ccb40398 100644 --- a/fs_storage/readme/USAGE.md +++ b/fs_storage/readme/USAGE.md @@ -75,6 +75,8 @@ for the following fields: - options - directory_path +When evaluating directory_path, `{db_name}` is replaced by the database name. + ## Migration from storage_backend The fs_storage addon can be used to replace the storage_backend addon. diff --git a/fs_storage/readme/newsfragments/db_name.feature b/fs_storage/readme/newsfragments/db_name.feature new file mode 100644 index 0000000000..81960069cc --- /dev/null +++ b/fs_storage/readme/newsfragments/db_name.feature @@ -0,0 +1 @@ +Replace {db_name} by the database name in directory_path