beancount / fava

Fava - web interface for Beancount
https://beancount.github.io/fava/
MIT License
1.97k stars 285 forks source link

Import broken on 1.23 #1501

Closed eglia closed 2 years ago

eglia commented 2 years ago

After updating to fava 1.23.0 or 1.23.1, importing is broken for me. When pressing the extract button for any file, the following exception occurs:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/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 "/usr/lib/python3.10/site-packages/fava/json_api.py", line 143, in _wrapper
    return json_success(res)
  File "/usr/lib/python3.10/site-packages/fava/json_api.py", line 50, in json_success
    return jsonify({"success": True, "data": data})
  File "/usr/lib/python3.10/site-packages/flask/json/__init__.py", line 342, in jsonify
    return current_app.json.response(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/flask/json/provider.py", line 106, in response
    return self._app.response_class(self.dumps(obj), mimetype="application/json")
  File "/usr/lib/python3.10/site-packages/fava/core/charts.py", line 99, in dumps
    return ENCODER.encode(obj)
  File "/usr/lib/python3.10/site-packages/simplejson/encoder.py", line 296, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/site-packages/simplejson/encoder.py", line 378, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.10/site-packages/fava/core/charts.py", line 82, in default
    return JSONEncoder.default(self, o)
  File "/usr/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 builtin_function_or_method is not JSON serializable

The importers work fine when using bean-extract and work fine using Fava 1.22.3.

yagebu commented 2 years ago

I can't reproduce this. Could you share the importer that you are using, it seems to add some data that Fava has trouble serialising to JSON.

eglia commented 2 years ago

So while trying to create a minimal example, I noticed that all my importers contained this code for the entries: beancount.core.data.new_metadata(file.name, id) id is not defined and I'm not sure where it came from, probably it was previously used as a variable. Since it's not defined as a variable, it refers to the builtin method id, which is obviously nonsense in this context. However, neither bean-extract nor fava<1.23 seemed to care about it. I changed my code to beancount.core.data.new_metadata(file.name, 1) and importing is now working again. Sorry for the noise.