-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Database connection serializer in Prefect #16557
Comments
hi @amanchaudhary-95 - did you try either of the suggestions given by the error? This often occurs when task inputs contain objects that cannot be cached like locks, file handles, or other system resources.
To resolve this, you can:
1. Exclude these arguments by defining a custom `cache_key_fn`
2. Disable caching by passing `cache_policy=NONE` for example, option 1 seems likely to work for your case |
Hi @zzstoatzz, Yes, I had tried both the options. With both the options, it will not cache the connection. |
if you need to cache the connection object (which is not a common pattern that I've seen personally) then you might need to write your own serializer. however if you're just trying to access the same connection object in different tasks, you could make it some kind of global and not pass it as a task argument note that the latter option will likely not work if you use |
hi @amanchaudhary-95 - i am going to close this issue, as I think there exists an escape hatch today via a custom cache key policy. Feel free to comment here if you think this should be reopened |
Bug summary
I'm trying to serialize a database connection. I want to make the connection persistent so that I don't need to connect it every task run. The issue is that the prefect cache is not able to serialize the connection. The code is below:
The code is working fine, and it can get the data from database but I'm getting below error in prefect consol:
Is there a way to serialize the database connection in Prefect or is there a way to make a database connection persistent so that I don't have to re-connect with it at each task run?
Version info
Additional context
I tried caching the same database connection in Streamlit using the st.cache_resource and the connection was persistent in it across all the sessions and runs. I'm not sure if similar caching is possible in prefect or not.
The text was updated successfully, but these errors were encountered: