From 9dc2fa7aa82b0e58c0e76915e60465ff18ff3a9e 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 b811e59d84..0446a85ecd 100644 --- a/fs_storage/models/fs_storage.py +++ b/fs_storage/models/fs_storage.py @@ -162,6 +162,13 @@ def __init__(self, env, ids=(), prefetch_ids=()): def _server_env_fields(self): return {"protocol": {}, "options": {}, "directory_path": {}} + 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 2379e3b398..851f5ae103 100644 --- a/fs_storage/readme/USAGE.md +++ b/fs_storage/readme/USAGE.md @@ -65,6 +65,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