跳至內容
選單
此問題已被標幟
2 回覆
386 瀏覽次數

In Odoo 19 there is some issue with importing

from stdnum import iban

ends with error FileNotFoundError: Can't open orphan path

Here is very simple module that just import iban package and it fails, I also try update stdnum, used the exact same as i have in .venv in odoo 18 nothing helps.

drive.google.com/file/d/1ALIuMRUjeWC8an3UXRvGK5eoOJUIWAQo/view?usp=sharing

Tested on: Mac, Linux, Windows same result

Anyone any idea what could be wrong?

Traceback (most recent call last):
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/http.py", line 2798, in __call__
    response = request._serve_db()
               ^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/http.py", line 2281, in _serve_db
    raise self._update_served_exception(exc)
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/http.py", line 2279, in _serve_db
    return service_model.retrying(serve_func, env=self.env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/service/model.py", line 184, in retrying
    result = func()
             ^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/http.py", line 2326, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/http.py", line 2541, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/addons/base/models/ir_http.py", line 357, in _dispatch
    result = endpoint(**request.params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/http.py", line 788, in route_wrapper
    result = endpoint(self, *args, **params_ok)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/addons/web/controllers/dataset.py", line 38, in call_button
    action = call_kw(request.env[model], method, args, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/service/model.py", line 93, in call_kw
    result = method(recs, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/addons/base/models/ir_module.py", line 70, in check_and_log
    return method(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/addons/base/models/ir_module.py", line 477, in button_immediate_install
    return self._button_immediate_function(self.env.registry[self._name].button_install)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/addons/base/models/ir_module.py", line 618, in _button_immediate_function
    registry = modules.registry.Registry.new(self.env.cr.dbname, update_module=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/tools/func.py", line 88, in locked
    return func(inst, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/orm/registry.py", line 185, in new
    load_modules(
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/modules/loading.py", line 449, in load_modules
    load_module_graph(
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/modules/loading.py", line 169, in load_module_graph
    load_openerp_module(package.name)
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/comunity/odoo/modules/module.py", line 496, in load_openerp_module
    __import__(qualname)
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/l10n_cz_systee/test_iban/__init__.py", line 1, in <module>
    from . import models
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/l10n_cz_systee/test_iban/models/__init__.py", line 1, in <module>
    from . import res_partner
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/l10n_cz_systee/test_iban/models/res_partner.py", line 2, in <module>
    from stdnum import iban
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/.venv/lib/python3.12/site-packages/stdnum/iban.py", line 56, in <module>
    _ibandb = numdb.get('iban')
              ^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/.venv/lib/python3.12/site-packages/stdnum/numdb.py", line 176, in get
    with reader(_get_resource_stream(name + '.dat')) as fp:
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/stanislavkurinec/_projekty/odoo-19.0+e/.venv/lib/python3.12/site-packages/stdnum/numdb.py", line 165, in _get_resource_stream
    return importlib.resources.files(__package__).joinpath(name).open('rb')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/resources/_adapters.py", line 139, in open
    raise FileNotFoundError("Can't open orphan path")
FileNotFoundError: Can't open orphan path
頭像
捨棄
作者 最佳答案

After Cybrosys recommendation here is the solution hope this will helps others too.
Just modify your primary __init__.py file like this 

import importlib.util
import stdnum

# Patch the package spec so importlib.resources can resolve data files
stdnum.__spec__ = importlib.util.spec_from_file_location(
stdnum.__name__, stdnum.__file__
)
from . import models
頭像
捨棄
最佳答案

Hi,

The error you are seeing when importing from stdnum import iban in Odoo 19 is not Odoo-specific but comes from the way the python-stdnum package loads resources in Python 3.12. The iban module relies on .dat files accessed via importlib.resources, and in Python 3.12 this system is stricter, so if the package metadata or resources are missing, it raises a “Can't open orphan path” error.

The first thing to check is the version of python-stdnum you are using, since proper support for Python 3.12 was added in version 1.19. Upgrading to the latest version usually resolves the issue. Another fix is to change the import style to import stdnum.iban as iban, which avoids problems with package lookups. If errors persist, verify that the .dat files (like iban.dat) exist inside your virtual environment’s stdnum folder; if not, reinstall the package.

As a workaround, you can also patch the __spec__ of the stdnum package in your Odoo module’s __init__.py before importing iban. However, the cleanest solution is to upgrade python-stdnum and adjust the import statement, which keeps your environment compatible with Python 3.12 without requiring custom patches.


Hope it helps

頭像
捨棄
作者

Hi,
thank you so much for your response. Based on your information I dig deeper and here’s the posibble reason:

1.19 (released in July 2022) still relied on older importlib.resources behavior.

Python 3.12 (Oct 2023) tightened the rules and started raising FileNotFoundError: Can't open orphan path if a resource isn’t declared correctly.

This exact issue was reported upstream
and fixed in python-stdnum 1.20 (released 2023-08-13) with improved compatibility for Python 3.12 resource loading.

But so far even python-stdum 2.1 doesn't fix this issue this is quite trap right now :/

相關帖文 回覆 瀏覽次數 活動
1
9月 25
960
0
12月 20
2673
1
7月 24
7684
0
1月 22
2621
3
10月 25
396