From dd3f495ba4928d7bd5dbe5003b0bbe8769f3e721 Mon Sep 17 00:00:00 2001 From: Ernad Husremovic Date: Thu, 16 Oct 2025 16:51:35 +0200 Subject: [PATCH] Fix _NamespacePath concatenation error in file_path function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert odoo.addons.__path__ to list before concatenation with [root_path] to fix TypeError when using Python 3.7+ namespace packages. Error: unsupported operand type(s) for +: '_NamespacePath' and 'list' Location: odoo/tools/misc.py:169 Added documentation explaining the fix in docs/PATCH_ADDONS_PATH.md 🤖 assisted by claude --- docs/PATCH_ADDONS_PATH.md | 48 +++++++++++++++++++ odoo-bringout-oca-ocb-base/odoo/tools/misc.py | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 docs/PATCH_ADDONS_PATH.md diff --git a/docs/PATCH_ADDONS_PATH.md b/docs/PATCH_ADDONS_PATH.md new file mode 100644 index 00000000..f02979ed --- /dev/null +++ b/docs/PATCH_ADDONS_PATH.md @@ -0,0 +1,48 @@ +# Fix for _NamespacePath Concatenation Error + +## Issue + +After upgrading, Odoo failed to start with the following error: + +``` +TypeError: unsupported operand type(s) for +: '_NamespacePath' and 'list' +``` + +This occurred in `odoo/tools/misc.py:169` in the `file_path()` function. + +## Root Cause + +In Python 3.7+, namespace packages use `_NamespacePath` objects for the `__path__` attribute. This special type cannot be directly concatenated with a Python list using the `+` operator. + +The problematic code was: +```python +addons_paths = odoo.addons.__path__ + [root_path] +``` + +When `odoo.addons.__path__` is a `_NamespacePath` object, attempting to add it to a list `[root_path]` raises a `TypeError`. + +## Solution + +Convert the `_NamespacePath` to a list before concatenation: + +```python +addons_paths = list(odoo.addons.__path__) + [root_path] +``` + +## File Modified + +- `odoo-bringout-oca-ocb-base/odoo/tools/misc.py` line 169 + +## Related Code + +The `file_path()` function is used throughout Odoo to: +- Verify file paths under known `addons_path` directories +- Locate module resources (icons, static files, etc.) +- Validate file access for security purposes + +This fix ensures the function can properly construct the list of addon paths to search. + +## References + +- Python namespace packages: [PEP 420](https://www.python.org/dev/peps/pep-0420/) +- Working commit reference: 3f19943cec2680164696765266fc0cdb4e9220c5 diff --git a/odoo-bringout-oca-ocb-base/odoo/tools/misc.py b/odoo-bringout-oca-ocb-base/odoo/tools/misc.py index 5dad940b..290f3cfa 100644 --- a/odoo-bringout-oca-ocb-base/odoo/tools/misc.py +++ b/odoo-bringout-oca-ocb-base/odoo/tools/misc.py @@ -166,7 +166,7 @@ def file_path(file_path, filter_ext=('',), env=None): :raise ValueError: if the file doesn't have one of the supported extensions (`filter_ext`) """ root_path = os.path.abspath(config['root_path']) - addons_paths = odoo.addons.__path__ + [root_path] + addons_paths = list(odoo.addons.__path__) + [root_path] if env and hasattr(env.transaction, '__file_open_tmp_paths'): addons_paths += env.transaction.__file_open_tmp_paths is_abs = os.path.isabs(file_path)