redstreet/fava_investor

Fava investor tab fails to load

kantskernel opened this issue · 8 comments

When I click on Fava Investor tab it fails to load. I reproduced using the example from:

https://github.com/redstreet/fava_investor/blob/main/fava_investor/pythonanywhere/

When I run investor assetalloc-class <beancount_file> it runs without issue.

I'm running on MacOS Ventura (arm) with the following:

beancount                2.3.5
beancount-reds-importers 0.5.1
click                    8.1.3
click-aliases            1.0.1
fava                     1.21
fava-investor            0.3.0
Flask                    2.2.2
Flask-Babel              2.0.0

Here's what I see in terminal:

Exception on /example-beancount-file/extension/Investor/ [GET]
Traceback (most recent call last):
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/flask/app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/fava/application.py", line 341, in extension_report
    content = render_template_string(template, extension=extension)
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/flask/templating.py", line 159, in render_template_string
    return _render(app, template, context)
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/flask/templating.py", line 130, in _render
    rv = template.render(context)
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 220, in top-level template code
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/fava_investor/__init__.py", line 21, in build_assetalloc_by_class
    return libassetalloc.assetalloc(accapi, self.config.get('asset_alloc_by_class', {}))
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/fava_investor/modules/assetalloc_class/libassetalloc.py", line 192, in assetalloc
    realacc = build_interesting_realacc(accapi, config.get('accounts_patterns', ['.*']))
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/fava_investor/modules/assetalloc_class/libassetalloc.py", line 156, in build_interesting_realacc
    realroot = accapi.realize()
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/fava_investor/common/favainvestorapi.py", line 23, in realize
    return g.filtered.root_account
  File "/Users/redacted/projects/test3-beans/venv-beans/lib/python3.9/site-packages/flask/ctx.py", line 52, in __getattr__
    raise AttributeError(name) from None
AttributeError: filtered

The only difference between the versions you posted and my setup is Flask, and I use Flask 2.0.1. You might want to try to see if using that version fixes that problem.

If not, unfortunately, I don't have access to a Mac, and am thus unable to debug on that platform. Other users here might help though (eg: see #55).

I tried a pip3 install --force-reinstall flask==2.0.1 but the issue persisted. I also then tried a fresh venv and set it up using this requirements.txt

https://github.com/redstreet/fava_investor/blob/main/requirements.txt

Still issue persisted. I've tried both safari and chrome.

If any other users on Mac have any ideas please let me know!

Also: I use Python 3.8.10. If it's easy for you to try it out with that, it's worth a shot.

I was able to get Python 3.8.13 setup pretty quickly but it still reproduced. I could probably try with an older MacOS (seems Big Sur has worked for others already). It does not seem likely that arm is the issue

Good to know, that more or less eliminates dependencies. I'm assuming you reinstalled fava_investor, fava, beancount, etc. for your Python 3.8, and verified that they are not using 3.9 (the traceback should make this obvious).

Something else I hadn't noticed: I'm using fava 1.22.3. Upstream fava did make a change around its filtering API, and I pushed a03223a and 7381a34, which are included in 0.3.0. So this may be the issue. You can check by either downgrading fava_investor to 0.2.7, or by upgrading fava to 1.22.3. Would be curious to know if the issue still reoccurs with those setups.

TL;DR, the following resolved the issue: pip3 install --force-reinstall fava==1.22.3

I'm assuming you reinstalled fava_investor, fava, beancount, etc. for your Python 3.8, and verified that they are not using 3.9 (the traceback should make this obvious).

I did, I used the same requirements.txt for reinstallation mentioned earlier

https://github.com/redstreet/fava_investor/blob/main/requirements.txt

The traceback did confirm as well:

Exception on /example-beancount-file/extension/Investor/ [GET]
Traceback (most recent call last):
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/fava/application.py", line 341, in extension_report
    content = render_template_string(template, extension=extension)
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/flask/templating.py", line 166, in render_template_string
    return _render(ctx.app.jinja_env.from_string(source), context, ctx.app)
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/flask/templating.py", line 128, in _render
    rv = template.render(context)
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 220, in top-level template code
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/fava_investor/__init__.py", line 21, in build_assetalloc_by_class
    return libassetalloc.assetalloc(accapi, self.config.get('asset_alloc_by_class', {}))
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/fava_investor/modules/assetalloc_class/libassetalloc.py", line 192, in assetalloc
    realacc = build_interesting_realacc(accapi, config.get('accounts_patterns', ['.*']))
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/fava_investor/modules/assetalloc_class/libassetalloc.py", line 156, in build_interesting_realacc
    realroot = accapi.realize()
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/fava_investor/common/favainvestorapi.py", line 23, in realize
    return g.filtered.root_account
  File "/Users/redacted/projects/test5-beans/test-py/lib/python3.8/site-packages/flask/ctx.py", line 51, in __getattr__
    raise AttributeError(name) from None

downgrading fava_investor to 0.2.7,

I tried this first (pip3 install --force-reinstall fava_investor==0.2.7) and had an issue that looked identical from safari/chrome but provided different output:

self.entries = self.ledger.root_tree
AttributeError: 'FavaLedger' object has no attribute 'root_tree'

Next I tried: pip3 install --force-reinstall fava==1.22.3 and this appears to have resolved all issues. There's some output in terminal that I need to look into but fava investor is loading:

FavaLedger.root_tree has been deprecated.
FavaLedger.entries has been deprecated.
FavaLedger.root_account has been deprecated.
FavaLedger.entries has been deprecated.
FavaLedger.entries has been deprecated.

Can't thank you enough!

Excellent, glad to hear, and most welcome!

Are you still on investor 0.2.7? Can you try to upgrade to 0.3.0? The deprecated warnings should not occur with 0.3.0. If they do, that's a bug.

TODO (for me): figure out the fava dependency version and update.

Just confirming -- upgrading investors to 0.3.0 did resolve the warnings.