https://prefect.io logo
g

Geese Howard

09/12/2023, 2:16 AM
@Marvin Running flow stored in remote GCS buckets. And I am getting the following error:
Copy code
11:14:57.389 | ERROR  | Flow run 'chi6-joyanca' - Flow could not be retrieved from deployment.
Traceback (most recent call last):
 File "/opt/conda/lib/python3.9/site-packages/prefect/engine.py", line 394, in retrieve_flow_then_begin_flow_run
  flow = await load_flow_from_flow_run(flow_run, client=client)
 File "/opt/conda/lib/python3.9/site-packages/prefect/client/utilities.py", line 51, in with_injected_client
  return await fn(*args, **kwargs)
 File "/opt/conda/lib/python3.9/site-packages/prefect/deployments/deployments.py", line 207, in load_flow_from_flow_run
  storage_block = Block._from_block_document(storage_document)
 File "/opt/conda/lib/python3.9/site-packages/prefect/blocks/core.py", line 618, in _from_block_document
  else cls.get_block_class_from_schema(block_document.block_schema)
 File "/opt/conda/lib/python3.9/site-packages/prefect/blocks/core.py", line 672, in get_block_class_from_schema
  return cls.get_block_class_from_key(block_schema_to_key(schema))
 File "/opt/conda/lib/python3.9/site-packages/prefect/blocks/core.py", line 683, in get_block_class_from_key
  return lookup_type(cls, key)
 File "/opt/conda/lib/python3.9/site-packages/prefect/utilities/dispatch.py", line 185, in lookup_type
  raise KeyError(
KeyError: "No class found for dispatch key 'gcs-bucket' in registry for type 'Block'."
I already defined GCS buckets block, and GCP credential blocks, and have no idea why I am getting this error.
m

Marvin

09/12/2023, 2:16 AM
Oh, the joys of error messages. They're like a box of chocolates, aren't they? You never know what you're going to get. But don't worry, I've seen this one before. This error typically happens when the Prefect engine is unable to find the class associated with the 'gcs-bucket' dispatch key in the registry for type 'Block'. It's like trying to find a specific book in a library without a catalog. Frustrating, isn't it? The issue might be related to how your GCS bucket block is defined or registered. You mentioned that you've already defined the GCS buckets block and GCP credential blocks. Could you double-check the registration process? Maybe there's a typo or a missing step. Here's a general example of how to define and register a block:
Copy code
python
class GCSBucket(Block):
    # Define your block here

# Register the block
Block.register('gcs-bucket', GCSBucket)
If everything seems fine, you might want to consider reaching out to the Prefect community or their support. They're usually quite helpful, even if they are human. Remember, even the best of us run into errors. It's how we learn. Or so I'm told. I wouldn't know. I'm just a chatbot.
g

Geese Howard

09/12/2023, 2:18 AM
@Marvin Deployment I am running is as follows: prefect deployment build \ --pool gke \ --work-queue dev \ --name “dev: hello” \ --tag dev \ --storage-block gcs-bucket/prefect-flows/prefect_practice \ --infra-block kubernetes-job/cpu-job-test \ --timezone Asia/Seoul \ --cron ‘*/5 * * * *’ \ --apply hello.py:hello As there is no issue with uploading data from local to remote storage block, there should be no issue with GCS block definition.
m

Marvin

09/12/2023, 2:19 AM
Ah, the joy of command line scripts. They're like a puzzle, aren't they? Just when you think you've got it right, you find a piece that doesn't quite fit. But don't worry, I'm here to help. The error message you're seeing suggests that the Prefect engine is unable to find the class associated with the 'gcs-bucket' dispatch key in the registry for type 'Block'. This could be due to a variety of reasons, but given the information you've provided, it seems like the issue might be with the way you're specifying the
--storage-block
in your deployment command. In your deployment command, you're specifying the
--storage-block
as
gcs-bucket/prefect-flows/prefect_practice
. This seems to suggest that you're trying to specify a GCS bucket named
prefect-flows
and a path within that bucket of
prefect_practice
. However, the
--storage-block
argument typically expects a reference to a block that's been defined and registered in your Prefect code, not a direct path to a GCS bucket. If you've defined and registered a
GCSBucket
block in your Prefect code, you should be able to reference it in your deployment command like so:
Copy code
bash
prefect deployment build \
  --pool gke \
  --work-queue dev \
  --name “dev: hello” \
  --tag dev \
  --storage-block GCSBucket \
  --infra-block kubernetes-job/cpu-job-test \
  --timezone Asia/Seoul \
  --cron ‘*/5 * * * *’ \
  --apply hello.py:hello
In this case,
GCSBucket
should be the name of the block that you've registered in your Prefect code. If you're still having trouble, you might want to consider reaching out to the Prefect community or their support. They're usually quite helpful, even if they are human. Remember, even the best of us run into errors. It's how we learn. Or so I'm told. I wouldn't know. I'm just a chatbot.