Getting this error while deploying the flow on Pre...
# ask-community
a
Getting this error while deploying the flow on PrefectCloud while locally executing it is working fine. We are trying to save the Results to GCS_RESULTS in buckets. Can anyone please assist with this? Unexpected error: PicklingError('Pickling client objects is explicitly not supported.\nClients have non-trivial state that is local and unpickleable.') Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/prefect/engine/runner.py", line 48, in inner new_state = method(self, state, *args, **kwargs) File "/usr/local/lib/python3.8/site-packages/prefect/engine/task_runner.py", line 900, in get_task_run_state result = self.result.write(value, **formatting_kwargs) File "/usr/local/lib/python3.8/site-packages/prefect/engine/results/gcs_result.py", line 75, in write binary_data = new.serializer.serialize(new.value) File "/usr/local/lib/python3.8/site-packages/prefect/engine/serializers.py", line 73, in serialize return cloudpickle.dumps(value) File "/usr/local/lib/python3.8/site-packages/cloudpickle/cloudpickle_fast.py", line 73, in dumps cp.dump(obj) File "/usr/local/lib/python3.8/site-packages/cloudpickle/cloudpickle_fast.py", line 563, in dump return Pickler.dump(self, obj) File "/usr/local/lib/python3.8/site-packages/google/cloud/client.py", line 166, in getstate raise PicklingError( _pickle.PicklingError: Pickling client objects is explicitly not supported. Clients have non-trivial state that is local and unpickleable.
k
Hey @aman gupta, it seems like you have a task that returns a
Client
or some like of database connection?
a
the task is returning a self object. class MyTask(Task): APP_NAME = __app_name__ def run(self, input_params): self.logger.info('Input Params:::: }'.format(input_params)) self.poperty1 = input_params.get('value1') self.property2 = input_params.get('value2') self.property3 = input_params.get('value3') self.logger.info('test value') return self ==> self.logger.info is saving logs to google cloud. ==> self.property1 , self.property2 , self.property3 is getting values from a dictionary. Can you assist me in finding where I am returning a Client or some kind of DB connection?
k
Task inputs and outputs need to be serializable by
cloudpickle
to be handed to Dask. I would check if you can serialize the
MyTask
class. It might be your logger also if it’s sending logs to cloud? Can you try
from prefect.utilities.debug import is_serializable
and then
is_serializable(MyTask)
or
is_serializable(flow)
a
--> Actually I am doing development on windows 10 enterprise 64 bit, that is why I am getting error "OSError: is_serializable is not supported on Windows". Can you please suggest some alternate way to check if it is serializable or not *-->*yes the logs are being sent to google cloud using self.logger.info()
k
Try
import cloudpickle
and then
cloudpickle.dumps(MyTask())
. Or you can try returning something other than
self
first. What is this task doing? Just logging the params?
a
--> I have tried returning a dictionary which is not having that logger and it is working fine. like this
Copy code
result_dict = {'val1': self.property1, 'value2': self.property2, 'value3': self.property3}

return result_dict
--> The task is just mapping the prams from a dictionary from a previous task and making a object of it and returning that object and also doing logging in between on cloud.
k
I think the logger to cloud contains a connection that can’t be pickled. You might have to attach this Handler inside the
run
method of the task and then use it but not return it with the
self
a
can you please provide me a small sample code....as I am not able to understand Handler...or should I proceed
k
How did you get your logger writing to google cloud?
But here is a sample snippet for writing to a file. You would need to attach the handler in each task.
You probably have some like like
logger.addHandler(GCPHandler)
to write to Google cloud. I suggest instead that you 1. Return the serializable stuff instead of self. Self returns a Task and you want to be dealing with the outputs, not returning the Task upon running. 2. Use the Prefect logger, and then you can add the handler to it inside the task