-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Handle cache failures that occur because of an error during processing, either because of a bug in our caching code, or a bug in the user's app.
These errors are currently swallowed by the hash error message handling, that displays a message to the user advising them to use hash_funcs to resolve their issue. While in reality, these errors are different from the ones that can be resolved by using hash_funcs.
The snippet below throws an error because strptime is not an attribute of datetime. This happens while we're analyzing the bytecode of function foo. However, this error is swallowed and we display the hash_funcs message even tho the solution is a bug fix in the user code.
import datetime
from streamlit.hashing import get_hash
@st.cache
def foo():
return datetime.strptime("12", "%H")
foo()
This snippet below throws an error because Path objects are incorrectly being hashed as if they were Files. We try calling tell() on the Path but that method doesn't exist on the instance. However, this error is swallowed and we display the hash_funcs message even tho the solution is a bug fix around Path handling.
import streamlit as st
from pathlib import Path
@st.cache
def foo():
return Path("file_in_current_directory.txt")
foo()
Related to:
- Improve function cache error message #992
- Hashing fails for pathlib.Path objects whose filename exists in the current directory #857
Solution
Distinguish these errors from actual can't hash this object errors, and display the original exception to the user for these cases.