I have a flow that when I run locally, works fine. Here’s my flow ```with Flow(PREFECT_FLOW_NAME, s...
s

Stephen Lloyd

over 3 years ago
I have a flow that when I run locally, works fine. Here’s my flow
with Flow(PREFECT_FLOW_NAME, storage=STORAGE, run_config=RUN_CONFIG) as flow:
    creds = get_credentials()
    conn = get_connection(creds)
    tables = get_tables()
    save_data = load_to_s3.map(tables, conn=unmapped(conn))
    conn.set_upstream(creds)
    save_data.set_upstream(tables)
    save_data.set_upstream(conn)
It’s failing on
get_connection
and the relevant code is:
@task
def get_credentials():
    return PrefectSecret(PREFECT_FLOW_NAME).run()

@task
def get_connection(creds):
    return connectors.get_redshift_connector(creds)

# from another file...
import redshift_connector


def get_redshift_connector(creds: dict) -> object:
    conn = redshift_connector.connect(
        host=creds['host'],
        database=creds['database'],
        user=creds['user'],
        password=creds['password']
    )
    return conn
When I move to running in ECS, it fails with the following trace…
Unexpected error: TypeError("cannot pickle 'Struct' object")
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 930, in get_task_run_state
    result = self.result.write(value, **formatting_kwargs)
  File "/usr/local/lib/python3.8/site-packages/prefect/engine/results/s3_result.py", line 71, 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 602, in dump
    return Pickler.dump(self, obj)
TypeError: cannot pickle 'Struct' object
<@ULVA73B9P> i am using prefect 3 Error encountered when computing cache key - result will not be ...
s

Spida45

10 months ago
@Marvin i am using prefect 3 Error encountered when computing cache key - result will not be persisted. Traceback (most recent call last): File "/home/prefect/production/code/CEP/.virtualenv/lib/python3.12/site-packages/prefect/task_engine.py", line 155, in compute_transaction_key key = self.task.cache_policy.compute_key( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/prefect/production/code/CEP/.virtualenv/lib/python3.12/site-packages/prefect/cache_policies.py", line 168, in compute_key policy_key = policy.compute_key( ^^^^^^^^^^^^^^^^^^^ File "/home/prefect/production/code/CEP/.virtualenv/lib/python3.12/site-packages/prefect/cache_policies.py", line 168, in compute_key policy_key = policy.compute_key( ^^^^^^^^^^^^^^^^^^^ File "/home/prefect/production/code/CEP/.virtualenv/lib/python3.12/site-packages/prefect/cache_policies.py", line 296, in compute_key return hash_objects(hashed_inputs, raise_on_failure=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/prefect/production/code/CEP/.virtualenv/lib/python3.12/site-packages/prefect/utilities/hashing.py", line 66, in hash_objects return stable_hash(cloudpickle.dumps((args, kwargs)), hash_algo=hash_algo) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/prefect/production/code/CEP/.virtualenv/lib/python3.12/site-packages/cloudpickle/cloudpickle.py", line 1529, in dumps cp.dump(obj) File "/home/prefect/production/code/CEP/.virtualenv/lib/python3.12/site-packages/cloudpickle/cloudpickle.py", line 1295, in dump return super().dump(obj) ^^^^^^^^^^^^^^^^^ _pickle.PicklingError: Can't pickle <class '__prefect_loader__.second_spectrum_fetch.SecondSpectrumFetchConfig'>: import of module '__prefect_loader__.second_spectrum_fetch' failed