Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need hash_func for type CompiledFFI #1188

Open
tc87 opened this issue Mar 6, 2020 · 7 comments
Open

Need hash_func for type CompiledFFI #1188

tc87 opened this issue Mar 6, 2020 · 7 comments

Comments

@tc87
Copy link

@tc87 tc87 commented Mar 6, 2020

Summary

A community member noticed a "cannot hash of type" issue. More information can be found in this forum discussion.

Full error message

This is the error the community member received:UnhashableType: Cannot hash object of type CompiledFFI

@tc87

This comment has been minimized.

Copy link
Author

@tc87 tc87 commented Mar 6, 2020

Additional context from user that may be helpful:

"It happens when trying to create a connection to a Snowflake database. I provide the code below for exhausitivity but I’m not sure it really helps, since the CompiledFFI class is not Snowflake-specific. Thing is I don’t even know where to find this class to implement a custom hash_func… And it is quite annoying cause I do need to cache the results of database queries.

Thanks for your great software and your assistance :slight_smile:

import snowflake.connector

@st.cache
def get_database_connection():
    return snowflake.connector.connect(
       user='XXXX',
       password='XXXX',
       account='XXXX'
    )

"

@RomeoDespres

This comment has been minimized.

Copy link

@RomeoDespres RomeoDespres commented Mar 9, 2020

Hi, I'm the community member! Here is the full error message:

UnhashableType: Cannot hash object of type CompiledFFI

While caching some code, Streamlit encountered an object of type CompiledFFI. You’ll
need to help Streamlit understand how to hash that type with the hash_funcs argument.
For example:

@st.cache(hash_funcs={CompiledFFI: my_hash_func})
def my_func(...):
    ...

Please see the hash_funcs documentation for more details.
Traceback:

  File "C:\Users\RomeoDespres\Desktop\CompiledFFi_bug\app.py", line 11, in <module>
    st.cache(default_backend)()
  File "c:\users\romeodespres\appdata\local\programs\python\python37\lib\copyreg.py",
line 65, in _reduce_ex
    raise TypeError("can't pickle %s objects" % base.__name__)

I've narrowed the problem down to the cryptography library (that is unrelated to Snowflake). Below is the full code to raise the issue:

from cryptography.hazmat.backends import default_backend
import streamlit as st

st.cache(default_backend)()

Thanks for helping :)

@jrhone

This comment has been minimized.

Copy link
Contributor

@jrhone jrhone commented Mar 11, 2020

Hi @RomeoDespres ,

Thanks for the additional information.

I just wanted to clarify, are you instantiating a default_backend in your code and including it in a cached function?

Or is the snowflake connection instantiating the default_backend? Asking since your initial example only mentioned snowflake. Thanks.

@RomeoDespres

This comment has been minimized.

Copy link

@RomeoDespres RomeoDespres commented Mar 11, 2020

Now you make me realize it was my code that used cryptography, not Snowflake. I made a mistake when reporting the issue on the community forum, sorry... I can edit the post there if you like.

@RomeoDespres

This comment has been minimized.

Copy link

@RomeoDespres RomeoDespres commented Mar 11, 2020

To be more precise, I was using cryptography to encrypt my Snowflake credentials. Hence the mistake.

@jrhone

This comment has been minimized.

Copy link
Contributor

@jrhone jrhone commented Mar 17, 2020

@jrhone

This comment has been minimized.

Copy link
Contributor

@jrhone jrhone commented Mar 18, 2020

If, given a CompiledFFI object (or an FFI object) you can extract the original C string, we could hash that.

Otherwise, not sure what to hash… Is it possible to hash the machine code?

@jrhone jrhone added enhancement and removed bug labels Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.