Repository: streamlit/streamlit

Issue:
st_in_cache_warning test is not working
# Summary

st_in_cache_warning.py is not working as expected . The three different cached functions that should do a st.write() are not doing anything.

# Steps to reproduce

1. run `streamlit run e2e/scripts/st_in_cache_warning.py`
2. see

## Expected behavior:

We should see two different paragraphs and one button.

## Actual behavior:

I'm only seeing the message:
```
    If this is failing locally, it could be because you have a browser with
    Streamlit open. Close it and the test should pass.
```

## Is this a regression?

That is, did this use to work the way you expected in the past?
yes

# Additional information

https://4870-204086862-gh.circle-artifacts.com/0/frontend/cypress/videos/st_in_cache_warning.spec.ts.mp4


Discussion:

Resolving patch:
diff --git a/lib/streamlit/caching.py b/lib/streamlit/caching.py
--- a/lib/streamlit/caching.py
+++ b/lib/streamlit/caching.py
@@ -250,7 +250,11 @@ def _read_from_disk_cache(key):
     except util.Error as e:
         LOGGER.error(e)
         raise CacheError('Unable to read from cache: %s' % e)
-    except FileNotFoundError:
+
+    except (
+            OSError,  # Python 2
+            FileNotFoundError  # Python 3
+        ):
         raise CacheKeyNotFoundError('Key not found in disk cache')
     return value, args_mutated
 
@@ -266,7 +270,7 @@ def _write_to_disk_cache(key, value, args_mutated):
     # In python 3, it's an open error in util.
     except (util.Error, struct.error) as e:
         LOGGER.debug(e)
-        # Cleanup file so we don't leave zero byte files.
+        # Clean up file so we don't leave zero byte files.
         try:
             os.remove(path)
         except (FileNotFoundError, IOError, OSError):
diff --git a/lib/streamlit/hashing.py b/lib/streamlit/hashing.py
--- a/lib/streamlit/hashing.py
+++ b/lib/streamlit/hashing.py
@@ -265,14 +265,19 @@ def _to_bytes(self, obj, context):
         elif inspect.iscode(obj):
             return self._code_to_bytes(obj, context)
         elif inspect.ismodule(obj):
+            # TODO: Figure out how to best show this kind of warning to the
+            # user. In the meantime, show nothing. This scenario is too common,
+            # so the current warning is quite annoying...
+            # st.warning(('Streamlit does not support hashing modules. '
+            #             'We did not hash `%s`.') % obj.__name__)
             # TODO: Hash more than just the name for internal modules.
-            st.warning(('Streamlit does not support hashing modules. '
-                        'We did not hash `%s`.') % obj.__name__)
             return self.to_bytes(obj.__name__)
         elif inspect.isclass(obj):
-            # TODO: Hash more than just the name of classes.
+            # TODO: Figure out how to best show this kind of warning to the
+            # user.
             st.warning(('Streamlit does not support hashing classes. '
                         'We did not hash `%s`.') % obj.__name__)
+            # TODO: Hash more than just the name of classes.
             return self.to_bytes(obj.__name__)
         elif isinstance(obj, functools.partial):
             # The return value of functools.partial is not a plain function:
@@ -288,6 +293,8 @@ def _to_bytes(self, obj, context):
                 # As a last resort, we pickle the object to hash it.
                 return pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
             except Exception:
+                # TODO: Figure out how to best show this kind of warning to the
+                # user.
                 st.warning('Streamlit cannot hash an object of type %s.' % type(obj))
 
     def _code_to_bytes(self, code, context):


Test patch: