The Code
First of all hereโs my code:
# importing mysql Connector .... nothing unusual
import mysql.connector as connection
# This function connects to an external database
def dbconn():
try:
return connection.connect(** st.secrets["mysql"])
st.info("DB connected")
except:
return None
st.info("DB NOT connected")
# This Variable stores the connection
DB_DATA = dbconn()
# Applying Cache
# The following function takes the DB_DATA variable in and does a lot of stuff with it
# For Example: Make Queries, printing to webpage, lots of pandas calculation
@st.cache(suppress_st_warning=True, hash_funcs={connection.network.MySQLTCPSocket: dbconn})
def my_func(mydb):
...<Code goes here>
NOTE:
my_func
is meant to render a whole display page, not just to perform queries and calculations
The Error
Now that we have the code out of the way, here is the error I am getting:
Here is the explaination:
My aim is to make queries inside my_func()
while also rendering outputs and graphs to the screen. This function is meant to serve as a whole webpage(there are also other functions like this).
But as you might have guessed this process is extremely SLOW, therefore I want to apply @st.cache
to it.
I have a feeling that I am doing something very stupid here since the error is a simple Type Error.
Any suggesstion on how do I fix it?
Also, did I provide sufficient info? Iโll provide more if need be