andreasgerstmayr / fava-portfolio-returns

fava-portfolio-returns shows portfolio returns in Fava
GNU General Public License v2.0
36 stars 2 forks source link

Error when trying to run on an exapl #1

Closed mrlimacz closed 1 year ago

mrlimacz commented 1 year ago

I am trying to get this extension running on an example provided in this repo. When trying to access a particular group, I get the error (stack below).

I am running fava in a conda environment with python=3.10.8, fava=1.23.1, and beancount=2.3.5. I bulit beangrow and fava-portfolio-returns via pip. To get beangrow working I had to downgrade protobuf to version 3.19.0 and pip prompted me about conflicts with googleapis-common-protos and google-api-core, so maybe the problem is there. Can you share requirements.txt for the environment you are running this in?

Processing account: Assets:US:ETrade:GLD
Processing account: Assets:US:ETrade:ITOT
Processing account: Assets:US:ETrade:VEA
Processing account: Assets:US:ETrade:VHT
Processing account: Assets:US:Vanguard:RGAGX
Processing account: Assets:US:Vanguard:VBMPX
Exception on /beancount/extension/PortfolioReturns/ [GET]
Traceback (most recent call last):
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/fava/application.py", line 360, in extension_report
    content = Markup(render_template_string(template, extension=extension))
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/flask/templating.py", line 159, in render_template_string
    return _render(app, template, context)
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/flask/templating.py", line 130, in _render
    rv = template.render(context)
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/jinja2/filters.py", line 1688, in do_tojson
    return htmlsafe_json_dumps(value, dumps=dumps, **kwargs)
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/jinja2/utils.py", line 658, in htmlsafe_json_dumps
    dumps(obj, **kwargs)
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/fava/core/charts.py", line 99, in dumps
    return ENCODER.encode(obj)
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/simplejson/encoder.py", line 296, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/simplejson/encoder.py", line 378, in iterencode
    return _iterencode(o, 0)
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/fava/core/charts.py", line 82, in default
    return JSONEncoder.default(self, o)
  File "/home/kamil/.local/miniconda3/envs/pta_test/lib/python3.10/site-packages/simplejson/encoder.py", line 272, in default
    raise TypeError('Object of type %s is not JSON serializable' %
TypeError: Object of type DataFrame is not JSON serializable

image

andreasgerstmayr commented 1 year ago

Hi @adamczykkt!

Yep, somehow this plugin didn't work anymore with the latest version of fava (or any of its dependencies). It should be fixed in the latest version:

git clone https://github.com/andreasgerstmayr/fava-portfolio-returns.git
cd fava-portfolio-returns
pipenv install
cd example
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python pipenv run fava example.beancount
andreasgerstmayr commented 1 year ago

I also downgraded protobuf, so the protobuf-workaround should be obsolete now.

mrlimacz commented 1 year ago

Awesome, works like a charm. Thanks!