posthog icon indicating copy to clipboard operation
posthog copied to clipboard

Cannot open dashboard: Out of range float values are not JSON compliant

Open sentry[bot] opened this issue 3 years ago • 1 comments

Sentry Issue: POSTHOG-5H3

ValueError: Out of range float values are not JSON compliant
(5 additional frame(s) were not displayed)
...
  File "rest_framework/utils/json.py", line 25, in dumps
    return json.dumps(*args, **kwargs)
  File "django_statsd/middleware.py", line 300, in _wrapper
    return f(*args, **kwargs)
  File "__init__.py", line 234, in dumps
    return cls(
  File "json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)

This occurs when accessing https://app.posthog.com/dashboard/47968

sentry[bot] avatar Sep 20 '22 11:09 sentry[bot]

Code to repro in shell:


dash=SharingConfiguration.objects.get(access_token='4dWpf1zFQe6JHoRAp6gggi5u6hnTMQ').dashboard
from posthog.api.dashboard import *

class O(object):
    action = None

class R():
    query_params = {}
    data = {}
    user = User.objects.get(email="[email protected]")


items=DashboardSerializer(context={"view":O(),"request": R()}).get_items(dash)
from rest_framework.utils import encoders, json
json.dumps(items, cls=encoders.JSONEncoder)


# Debugging the specific failure
from copy import *
i = deepcopy(items[12])
json.dumps(i, cls=encoders.JSONEncoder) #fails
del i['result'][0]['aggregated_value']
del i['result'][1]['aggregated_value']
json.dumps(i, cls=encoders.JSONEncoder) #succeeds

The originating dashboard item is doing a formula A/B which is leading to float('inf') to be returned as a result, which causes the encoding failure.

This seems like a trends as well as insights bug - 0/0 division shouldn't make the whole dashboard unusable.

cc @Twixes @mariusandra @EDsCODE

macobo avatar Sep 20 '22 12:09 macobo