Someone have idea on how to get rid this error?

AttributeError: Can’t pickle local object ‘CustomComponent.create_instance..marshall_component..deserialize_component’


File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/", line 565, in _run_script
    exec(code, module.__dict__)File "/app/", line 950, in <module>
    light_curve()File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/runtime/caching/", line 188, in __call__
    return self._get_or_create_cached_value(args, kwargs)File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/runtime/caching/", line 211, in _get_or_create_cached_value
    return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/runtime/caching/", line 271, in _handle_cache_miss
    cache.write_result(value_key, computed_value, messages)File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/runtime/", line 311, in wrapped_func
    result = non_optional_func(*args, **kwargs)File "/app/.heroku/python/lib/python3.9/site-packages/streamlit/runtime/caching/", line 580, in write_result
    pickled_entry = pickle.dumps(multi_cache_results)

To fix this issue, you need to modify your code so that the marshall_component method can be pickled. One solution would be to move the marshall_component method out of the create_instance method and define it as a standalone function or a method of the CustomComponent class

I had the same issue due to caching; essentially, I wanted to download some data from MongoDB as DataFrame and cache the result.


def download_data(username):
    # Instantiate Mongo client
    # Download data as DataFrame for user 'username'

return downloaded_dataframe

I managed to fix this by passing the client as input, with its name preceded by “_”, so that Streamlit does not cache it:


def download_data(_client, username):

    # Download data as DataFrame for user 'username'

return downloaded_dataframe

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.