Skip to content

Conversation

@S-PANDIYAN
Copy link

@S-PANDIYAN S-PANDIYAN commented Jan 1, 2026

Docs: clarify picklable requirement for st.cache_resource

Clarifies that st.cache_resource requires pickle-able objects in addition to
being hashable, aligning the documentation with current caching behavior and
addressing confusion reported in #1399.

📚 Context

This change clarifies a documented requirement mismatch discussed in #1399,
where st.cache_resource requires objects to be pickle-able in addition to
being hashable.

🧠 Description of Changes

Added a documentation note explaining that st.cache_resource requires
pickle-able objects in addition to being hashable.

This helps prevent confusion around errors such as: TypeError: cannot pickle 'function' object

💥 Impact

Size:Small

🌐 References

#1399 — Error (TypeError: cannot pickle 'function' object) thrown in
st.cache_resource is confusing because the documentation previously mentioned
only hashability, while pickle-ability is also required.

📜 Contribution License Agreement

By submitting this pull request, you agree that all contributions to this project
are made under the Apache 2.0 license

…picklable requirement for st.cache_resource

Clarifies that `st.cache_resource` requires pickle-able objects in addition
to being hashable, aligning the documentation with current caching behavior
and addressing confusion reported in streamlit/streamlit#13480.
@S-PANDIYAN S-PANDIYAN requested a review from a team as a code owner January 1, 2026 16:07
**hashable**. Objects that contain non-pickleable elements (such as functions)
may raise errors like `TypeError: cannot pickle 'function' object`.

</Note>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems OK to me, it might be good to go into a bit more detail on the reason for the implementation. For example,

Streamlit's rerun model requires content-based hashing which is provided by python's __reduce__() method which means that objects must not only be hashable but also pickle-able. Objects that contain non-pickleable elements (such as functions) may raise errors like TypeError: cannot pickle 'function' object.

I am wondering whether we should change the actual error. Do you have any suggestions @sfc-gh-dmatthews

@S-PANDIYAN
Copy link
Author

S-PANDIYAN commented Jan 6, 2026

@sfc-gh-lwilby Thanks for the suggestion! That makes sense.
I’ll update the documentation to explain the rerun model, content-based hashing via reduce(), and why non-pickleable objects (like functions) can cause errors such as `TypeError: cannot pickle 'function' object.

@S-PANDIYAN
Copy link
Author

Docs: clarify picklable requirement for st.cache_resource

Clarifies that st.cache_resource requires pickle-able objects in addition to
being hashable, aligning the documentation with current caching behavior and
addressing confusion reported in #1399.

📚 Context

This change clarifies a documented requirement mismatch discussed in #1399,
where st.cache_resource requires objects to be pickle-able in addition to
being hashable.

🧠 Description of Changes

Added a documentation note explaining that st.cache_resource requires
pickle-able objects in addition to being hashable.

This helps prevent confusion around errors such as: TypeError: cannot pickle 'function' object

💥 Impact

Size:Small

🌐 References

#1399 — Error (TypeError: cannot pickle 'function' object) thrown in
st.cache_resource is confusing because the documentation previously mentioned
only hashability, while pickle-ability is also required.

📜 Contribution License Agreement

By submitting this pull request, you agree that all contributions to this project
are made under the Apache 2.0 license

Docs: clarify why st.cache_resource requires pickleable objects
@sfc-gh-dmatthews sfc-gh-dmatthews self-assigned this Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants