ContactEngineering / topobank

Create, visualize, analyze, share, and publish digital surface twins
https://contact.engineering
MIT License
8 stars 3 forks source link

Contact Mechanics: Out of range float values are not JSON compliant #797

Closed mcrot closed 1 year ago

mcrot commented 2 years ago

This recently happened during display of contact mechanics data:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/opt/conda/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/conda/lib/python3.7/contextlib.py", line 74, in inner
    return func(*args, **kwds)
  File "/opt/conda/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/app/topobank/analysis/views.py", line 1473, in contact_mechanics_data
    plots_json = {pn: json.dumps(json_item(plots[pn])) for pn in plots}
  File "/app/topobank/analysis/views.py", line 1473, in <dictcomp>
    plots_json = {pn: json.dumps(json_item(plots[pn])) for pn in plots}
  File "/opt/conda/lib/python3.7/site-packages/bokeh/embed/standalone.py", line 370, in json_item
    docs_json = standalone_docs_json([model])
  File "/opt/conda/lib/python3.7/site-packages/bokeh/embed/util.py", line 253, in standalone_docs_json
    docs_json, render_items = standalone_docs_json_and_render_items(models)
  File "/opt/conda/lib/python3.7/site-packages/bokeh/embed/util.py", line 294, in standalone_docs_json_and_render_items
    docs_json[docid] = doc.to_json()
  File "/opt/conda/lib/python3.7/site-packages/bokeh/document/document.py", line 901, in to_json
    doc_json = self.to_json_string()
  File "/opt/conda/lib/python3.7/site-packages/bokeh/document/document.py", line 930, in to_json_string
    return serialize_json(json, indent=indent)
  File "/opt/conda/lib/python3.7/site-packages/bokeh/core/json_encoder.py", line 166, in serialize_json
    return json.dumps(obj, cls=BokehJSONEncoder, allow_nan=False, indent=indent, separators=separators, sort_keys=True, **kwargs)
  File "/opt/conda/lib/python3.7/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/opt/conda/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/opt/conda/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)

Exception Type: ValueError at /analysis/card/contact-mechanics/data
Exception Value: Out of range float values are not JSON compliant
Request information:
USER: *********************

GET: No GET data

POST:
analysis_id = '330554'
pastewka commented 1 year ago

We now have our own JSON encoder that handles some edge cases. I have not seen this occur recently.