question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Streamlit failed to hash an object

See original GitHub issue

I am trying to get the DataFrame Demo from streamlit hello to work. I am running this using Anaconda and Python 3.6.

I get the following error in the browser:

Streamlit cannot hash an object of type <class 'os._Environ'>.,

More information: to prevent unexpected behavior, Streamlit tries to detect mutations in cached objects so it can alert the user if needed. However, something went wrong while performing this check.

Please file a bug.

To stop this warning from showing in the meantime, try one of the following:

Preferred: modify your code to avoid using this type of object.
Or add the argument ignore_cache=True to the st.cache decorator.

I get a bunch of additional errors on Streamlit failed to hash an object of type <class 'function'>.,

And then this error blob:

TypeError: object supporting the buffer API required
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/ScriptRunner.py", line 306, in _run_script exec(code, module.__dict__)
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/hello.py", line 334, in <module> run()
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/hello.py", line 308, in run demo()
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/hello.py", line 247, in data_frame_demo df = get_UN_data()
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/caching.py", line 544, in wrapped_func return get_or_set_cache()
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/caching.py", line 509, in get_or_set_cache code_hasher.update(func)
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/hashing.py", line 185, in update self._update(self.hasher, obj, context)
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/hashing.py", line 217, in _update hasher.update(b)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
cwernercommented, Oct 3, 2019

same here, macos, conda, python 3.7.4

1reaction
tvstcommented, Oct 14, 2019

Released as 0.48.1

More info: When you st.cache a function, Streamlit’s caching mechanism traverses all function calls inside it to track whether the called function’s body was edited since the cached function was last cached. And Streamlit already ignored “library” functions, since those can be assumed to be unmodified.

However, the way we defined library functions was “functions that were defined outside your current working directory its subfolders”. But this broke whenever your Python environment was placed inside the cwd!

So since version 0.48.1 we define “library function” as any function that was defined:

  • Outside your current working directory its subfolders
  • In a blacklisted folder:
    • The default blacklist is:
      "**/.*",
      "**/anaconda",
      "**/anaconda2",
      "**/anaconda3",
      "**/miniconda",
      "**/miniconda2",
      "**/miniconda3",
      "**/venv",
      "**/virtualenv",
      "**/pyenv",
      
    • Plus anything you specify with the Streamlit config option server.folderWatchBlacklist.

In addition, we also added this explanation to our error message:

This error can occur when your virtual environment lives in the same folder as your project, since that makes it hard for Streamlit to understand which files it should check. If you think that’s what caused this, please add the following to ~/.streamlit/config.toml:

[server]
folderWatchBlacklist = ['foldername']

…where foldername is the relative or absolute path to the folder where you put your virtual environment.


Of course, this still doesn’t solve the underlying problem of why those library functions were not hashable in the first place. We are working on that right now, but since there are a few different cases where things may not be hashable, I’d rather create one bug for each case than have a long-stanging bug with lots of mixed conversations.

Also, for almost everyone who reported this issue, the script that caused the bug was streamlit hello (which we know is 100% hashable!) and the tracebacks provided show the error was always due to library functions not being hashable (which is what we fixed now). So I’ll close this bug now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UnhashableType: Cannot hash object of type _thread._local
I keep getting the same error returned when I use st.cache before a function doing a complex query & pandas manipulation.
Read more >
Caching issues - Streamlit Docs
Streamlit raises this error whenever it encounters a type it doesn't know how to hash. This could be either when hashing the inputs...
Read more >
How to cache unsupported objects? - Using Streamlit
I've a function which accepts a MSExperiment instance as argument and I get the error: Streamlit cannot hash an object of type <class...
Read more >
Cannot hash object of type _json.Scanner - Using Streamlit
Hi there! I'm using st.cache on this function which requests data from Coin Market Cap and then parses it using Beautiful Soup.
Read more >
Hashing error in experimental_memo(), but not cache()
Getting the following error, but the type referenced is clearly hashable (and works with cache() ):. UnhashableParamError : Cannot hash ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found