beancount / beangrow

Returns calculations on portfolios in Beancount
GNU General Public License v2.0
55 stars 21 forks source link

Protobuf TypeError: Descriptors cannot be created directly. #29

Open AlphaJack opened 3 months ago

AlphaJack commented 3 months ago

Hi, I encountered this issue:

Starting Fava on http://127.0.0.1:5000
Exception on /accounting/editor/ [GET]
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/flask/app.py", line 1482, in full_dispatch_request
    rv = self.preprocess_request()
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/flask/app.py", line 1969, in preprocess_request
    url_func(request.endpoint, request.view_args)
  File "/usr/lib/python3.12/site-packages/fava/application.py", line 230, in _pull_beancount_file
    fava_app.config["LEDGERS"] = _ledger_slugs_dict(
                                 ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/fava/application.py", line 107, in _ledger_slugs_dict
    for ledger in ledgers:
  File "/usr/lib/python3.12/site-packages/fava/application.py", line 231, in <genexpr>
    FavaLedger(filepath)
  File "/usr/lib/python3.12/site-packages/fava/core/__init__.py", line 265, in __init__
    self.load_file()
  File "/usr/lib/python3.12/site-packages/fava/core/__init__.py", line 292, in load_file
    self.extensions.load_file()
  File "/usr/lib/python3.12/site-packages/fava/core/extensions.py", line 42, in load_file
    extensions, errors = find_extensions(
                         ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/fava/ext/__init__.py", line 137, in find_extensions
    module = importlib.import_module(name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/usr/lib/python3.12/site-packages/fava_portfolio_returns/__init__.py", line 19, in <module>
    from beangrow import investments  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/beangrow/investments.py", line 38, in <module>
    from beangrow.config_pb2 import Config
  File "/usr/lib/python3.12/site-packages/beangrow/config_pb2.py", line 36, in <module>
    _descriptor.FieldDescriptor(
  File "/usr/lib/python3.12/site-packages/google/protobuf/descriptor.py", line 621, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
^CKeyboard interrupt received: stopping Fava

I already try to rebuild the beangrow and fava_portfolio_returns, but without success. I had to comment out the fava_portfolio_returns plugin to access Fava.

On my system I have:

protobuf 27.1-2
    Protocol Buffers - Google's data interchange format
protobuf-c 1.5.0-3
    Protocol Buffers implementation in C
python-protobuf 27.1-2
    Python 3 bindings for Google Protocol Buffers
andreasgerstmayr commented 3 months ago

afaics this will be resolved with #22.

In the meantime, you can use a virtualenv for Python dependencies instead of the system packages and downgrade protobuf to version 3.20 or lower. Regarding fava-portfolio-returns: I set the protobuf dependency to <3.21: https://github.com/andreasgerstmayr/fava-portfolio-returns/blob/4c76fe60b412875c453bcafa81c275142e8bfe46/pyproject.toml#L11, so it should work out of the box if the dependencies are resolved correctly.