mlem icon indicating copy to clipboard operation
mlem copied to clipboard

models that `return None` fail while served with streamlit

Open aguschin opened this issue 3 years ago • 0 comments

how to reproduce

# fx.py
from mlem.api import save


def f(x): return None

save(f, "fx", sample_data="1")
$ python fx.py
$ mlem serve streamlit -m fx

When you open http://0.0.0.0:80 and click "submit", you get this traceback in UI (and in CLI also):

2022-12-20 12:38:30.832 Uncaught app exception
Traceback (most recent call last):
  File "/Users/aguschin/.local/share/virtualenvs/mlem-Utz6DvOn/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 564, in _run_script
    exec(code, module.__dict__)
  File "/private/var/folders/tv/l60j0x050p536g3bh8g2w1n80000gn/T/mlem_streamlit_script_i8mkxc4l/script.py", line 74, in <module>
    response = getattr(client, method_name)(
  File "/Users/aguschin/Git/iterative/mlem/mlem/runtime/client.py", line 155, in __call__
    return self.method.returns.get_serializer().deserialize(out)
  File "/Users/aguschin/Git/iterative/mlem/mlem/core/data_type.py", line 171, in deserialize
    return self.serializer.deserialize(self.data_type, obj)
  File "/Users/aguschin/Git/iterative/mlem/mlem/core/data_type.py", line 380, in deserialize
    return data_type.to_type(obj)
TypeError: NoneType takes no arguments

This is due to FastAPI returning null I assume. Ideally, this should return just None. This is a low priority since I believe not much would want to use models that sometimes return None, but this is a bug still and better be fixed.

aguschin avatar Dec 20 '22 06:12 aguschin