Skip to content

Commit

Permalink
fix for JSON serialization in Fava 1.26.1
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasgerstmayr committed Sep 24, 2023
1 parent 8e37bc1 commit 3f820c1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 59 deletions.
96 changes: 41 additions & 55 deletions example/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions src/fava_dashboards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import yaml
from collections import namedtuple
from functools import cached_property
from beancount.core.inventory import Inventory
from beancount.query.query import run_query
from fava.application import render_template_string
from fava.context import g
from fava.core.conversion import simple_units
from fava.ext import FavaExtensionBase
from fava.helpers import FavaAPIError
from fava.context import g
from fava.application import render_template_string

Config = namedtuple("Config", ["dashboards_path"])

Expand Down Expand Up @@ -69,8 +71,16 @@ def process_jinja2(self, ledger, panel):
raise FavaAPIError(f"Failed to parse template {template}: {ex}")

def sanitize_panel(self, ledger, panel):
"""remove fields which are not JSON serializable"""
"""replace or remove fields which are not JSON serializable"""
for query in panel.get("queries", []):
if "result" in query:
for i, row in enumerate(query["result"]):
for k, v in row._asdict().items():
if isinstance(v, Inventory):
query["result"][i] = query["result"][i]._replace(
**{k: simple_units(v)}
)

if "result_types" in query:
del query["result_types"]

Expand Down Expand Up @@ -101,5 +111,4 @@ def bootstrap(self, dashboard_id):
return {
"ledger": ledger,
"dashboards": dashboards,
"dashboardId": dashboard_id,
}

0 comments on commit 3f820c1

Please sign in to comment.