Rasmus
08/04/2025, 11:01 AMFailed to submit flow run 'e18616a4-4209-4006-95e2-8afb937e7904' to infrastructure.
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/prefect/workers/base.py", line 1258, in _submit_run_and_capture_errors
configuration = await self._get_configuration(flow_run)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/workers/base.py", line 1359, in _get_configuration
configuration = await self.job_configuration.from_template_and_values(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/client/utilities.py", line 99, in with_injected_client
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/workers/base.py", line 199, in from_template_and_values
return cls(**populated_configuration)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 253, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for CloudRunWorkerJobConfiguration
job_body
Value error, Job is missing required attributes at the following paths: /apiVersion, /kind, /metadata, /spec [type=value_error, input_value={'client': 'prefect', 'te..., 'launchStage': 'BETA'}, input_type=dict]
For further information visit <https://errors.pydantic.dev/2.11/v/value_error>
12:59:39 PM
prefect.flow_runs.worker
Reported flow run 'e18616a4-4209-4006-95e2-8afb937e7904' as crashed: Flow run could not be submitted to infrastructure:
1 validation error for CloudRunWorkerJobConfiguration
job_body
Value error, Job is missing required attributes at the following paths: /apiVersion, /kind, /metadata, /spec [type=value_error, input_value={'client': 'prefect', 'te..., 'launchStage': 'BETA'}, input_type=dict]
For further information visit <https://errors.pydantic.dev/2.11/v/value_error>
Marvin
08/04/2025, 11:01 AMMarvin
08/04/2025, 11:02 AMprefect-gcp
installed:
bash
pip install -U prefect-gcp
2. When creating your work pool, ensure you're using the correct base job template. You can create a new Cloud Run work pool with:
bash
prefect work-pool create my-cloud-run-pool --type cloud-run
3. Your worker configuration should include the following required fields:
- apiVersion
- kind
- metadata
- spec
These should be automatically included in the base job template, but you might need to verify your work pool configuration. You can check your work pool configuration with:
bash
prefect work-pool inspect my-cloud-run-pool
4. Make sure you have set the necessary environment variables:
bash
export PREFECT_API_KEY="your-api-key"
export PREFECT_API_URL="your-api-url"
5. If you're customizing the job configuration, ensure you're maintaining the required Kubernetes-style structure. The job body should look something like this:
yaml
apiVersion: <http://run.googleapis.com/v1|run.googleapis.com/v1>
kind: Job
metadata:
name: prefect-job
spec:
template:
spec:
containers:
- image: your-image
Could you share:
1. How did you create your work pool?
2. Are you using any custom job configuration?
3. What version of prefect-gcp
are you using?
This will help me provide more specific guidance for your setup.
Also, I notice you're using Python 3.12. While this should work, you might want to consider using Python 3.11 for now as it's more thoroughly tested with Prefect and its integrations.Rasmus
08/04/2025, 11:28 AMMarvin
08/04/2025, 11:28 AMMarvin
08/04/2025, 11:29 AMbash
pip install prefect-gcp
2. Create a new work pool specifically for Cloud Run (if you haven't already):
bash
prefect work-pool create "cloud-run-pool" --type cloud-run
3. The error you're seeing suggests that the job template is missing required fields. Let's inspect your current work pool configuration:
bash
prefect work-pool inspect "cloud-run-pool"
Could you share:
1. The output of the work pool inspection command?
2. What version of prefect-gcp
are you using? (pip show prefect-gcp
)
3. Are you using any custom job template modifications?
The error specifically mentions missing:
- /apiVersion
- /kind
- /metadata
- /spec
These should be automatically included in the default template, so the fact that they're missing suggests either:
1. A version mismatch between Prefect and prefect-gcp
2. An incorrect work pool type
3. Or a corrupted/modified job template
Also, make sure your GCP service account has the necessary permissions:
- Cloud Run Developer (roles/run.developer
)
- Service Account User (roles/iam.serviceAccountUser
)
Could you provide the requested information so I can give you more specific guidance on fixing this issue?Rasmus
08/04/2025, 11:30 AMWorkPool(
id='573bb603-e131-4558-ad9c-8d2d78807ee5',
created=DateTime(2025, 8, 4, 11, 19, 46, 601253, tzinfo=Timezone('UTC')),
updated=DateTime(2025, 8, 4, 11, 22, 58, 303694, tzinfo=Timezone('UTC')),
name='cloud-run-work-pool',
description='',
type='cloud-run-v2',
base_job_template={
'variables': {
'type': 'object',
'properties': {
'cpu': {
'type': 'string',
'title': 'CPU',
'default': '500m',
'description': 'The CPU to allocate to the Cloud Run job.'
},
'env': {
'type': 'object',
'title': 'Environment Variables',
'description': 'Environment variables to set when starting a flow run.',
'additionalProperties': {'type': 'string'}
},
'args': {
'type': 'array',
'items': {'type': 'string'},
'title': 'Args',
'description': "The arguments to pass to the Cloud Run Job V2's entrypoint command."
},
'name': {
'type': 'string',
'title': 'Name',
'default': 'prefect-worker',
'description': 'Name given to infrastructure created by a worker.'
},
'image': {
'type': 'string',
'title': 'Image Name',
'default': 'prefecthq/prefect:3-latest',
'description': 'The image to use for the Cloud Run job. If not provided the default Prefect image
will be used.'
},
'labels': {
'type': 'object',
'title': 'Labels',
'description': 'Labels applied to infrastructure created by a worker.',
'additionalProperties': {'type': 'string'}
},
'memory': {
'type': 'string',
'title': 'Memory',
'default': '512Mi',
'example': '512Mi',
'pattern': '^\\d+(?:G|Gi|M|Mi)$',
'description': 'The memory to allocate to the Cloud Run job along with the units, whichcould be: G,
Gi, M, Mi.'
},
'region': {
'type': 'string',
'title': 'Region',
'default': 'europe-north2',
'description': 'The region in which to run the Cloud Run job'
},
'command': {
'type': 'string',
'title': 'Command',
'description': 'The command to use when starting a flow run. In most cases, this should be left
blank and the command will be automatically generated by the worker.'
},
'timeout': {
'type': 'integer',
'title': 'Job Timeout',
'default': 600,
'maximum': 86400,
'description': 'The length of time that Prefect will wait for a Cloud Run Job to complete before
raising an exception (maximum of 86400 seconds, 1 day).',
'exclusiveMinimum': 0
},
'keep_job': {
'type': 'boolean',
'title': 'Keep Job After Completion',
'default': False,
'description': 'Keep the completed Cloud run job on Google Cloud Platform.'
},
'credentials': {
'allOf': [{'$ref': '#/definitions/GcpCredentials'}],
'title': 'GCP Credentials',
'description': 'The GCP Credentials used to connect to Cloud Run. If not provided credentials will
be inferred from the local environment.'
},
'max_retries': {
'type': 'integer',
'title': 'Max Retries',
'default': 0,
'description': 'The number of times to retry the Cloud Run job.'
},
'launch_stage': {
'enum': [
'ALPHA',
'BETA',
'GA',
'DEPRECATED',
'EARLY_ACCESS',
'PRELAUNCH',
'UNIMPLEMENTED',
'LAUNCH_TAG_UNSPECIFIED'
],
'type': 'string',
'title': 'Launch Stage',
'default': 'BETA',
'description': 'The launch stage of the Cloud Run Job V2. See
<https://cloud.google.com/run/docs/about-features-categories> for additional details.'
},
'vpc_connector_name': {
'type': 'string',
'title': 'VPC Connector Name',
'description': 'The name of the VPC connector to use for the Cloud Run job.'
},
'service_account_name': {
'type': 'string',
'title': 'Service Account Name',
'default': '<mailto:prefect-worker-sa@infrastructure-467509.iam.gserviceaccount.com|prefect-worker-sa@infrastructure-467509.iam.gserviceaccount.com>',
'example': '<mailto:service-account@example.iam.gserviceaccount.com|service-account@example.iam.gserviceaccount.com>',
'description': 'The name of the service account to use for the task execution of Cloud Run Job. By
default Cloud Run jobs run as the default Compute Engine Service Account.'
}
},
'definitions': {
'GcpCredentials': {
'type': 'object',
'title': 'GcpCredentials',
'properties': {
'project': {
'type': 'string',
'title': 'Project',
'description': 'The GCP project to use for the client.'
},
'service_account_file': {
'type': 'string',
'title': 'Service Account File',
'format': 'path',
'description': 'Path to the service account JSON keyfile.'
},
'service_account_info': {
'type': 'object',
'title': 'Service Account Info',
'description': 'The contents of the keyfile as a dict.'
}
},
'description': "Block used to manage authentication with GCP. Google authentication is\nhandled via
the `google.oauth2` module or through the CLI.\nSpecify either one of service `account_file` or `service_account_info`;
if both\nare not specified, the client will try to detect the credentials following Google's\n[Application Default
Credentials](<https://cloud.google.com/docs/authentication/application-default-credentials>).\nSee Google's
[Authentication documentation](<https://cloud.google.com/docs/authentication#service-accounts>)\nfor details on inference
and recommended authentication patterns.",
'secret_fields': ['service_account_info.*'],
'block_type_slug': 'gcp-credentials',
'block_schema_references': {}
}
},
'description': 'Default variables for the Cloud Run worker V2.\n\nThe schema for this class is used to
populate the `variables` section of the\ndefault base job template.'
},
'job_configuration': {
'env': '{{ env }}',
'name': '{{ name }}',
'labels': '{{ labels }}',
'region': '{{ region }}',
'command': '{{ command }}',
'timeout': '{{ timeout }}',
'job_body': {
'client': 'prefect',
'template': {
'template': {
'timeout': '{{ timeout }}',
'vpcAccess': {'connector': '{{ vpc_connector_name }}'},
'containers': [
{
'env': [],
'args': '{{ args }}',
'image': '{{ image }}',
'command': '{{ command }}',
'resources': {'limits': {'cpu': '{{ cpu }}', 'memory': '{{ memory }}'}}
}
],
'maxRetries': '{{ max_retries }}',
'serviceAccount': '{{ service_account_name }}'
}
},
'launchStage': '{{ launch_stage }}'
},
'keep_job': '{{ keep_job }}',
'credentials': '{{ credentials }}'
}
},
status=WorkPoolStatus.READY,
storage_configuration=WorkPoolStorageConfiguration(),
default_queue_id='724fdd7c-25f5-4332-bedc-93e7d5fdb3a7'
)
Marvin
08/04/2025, 11:30 AMRasmus
08/04/2025, 11:31 AMMarvin
08/04/2025, 11:31 AMRasmus
08/04/2025, 11:32 AMMarvin
08/04/2025, 11:32 AMRasmus
08/04/2025, 11:32 AMMarvin
08/04/2025, 11:32 AMMarvin
08/04/2025, 11:32 AMbash
prefect work-pool delete cloud-run-work-pool # Delete the existing pool
prefect work-pool create cloud-run-work-pool --type cloud-run
2. Let's verify the version of prefect-gcp you're using:
bash
pip install --upgrade prefect-gcp
3. The error you're seeing suggests that the job template isn't being properly populated. Let's try to set up a minimal working configuration. Create a file called job-template.json
with this content:
json
{
"job_body": {
"apiVersion": "<http://run.googleapis.com/v1|run.googleapis.com/v1>",
"kind": "Job",
"metadata": {
"name": "prefect-job"
},
"spec": {
"template": {
"spec": {
"containers": [
{
"image": "prefecthq/prefect:3-latest",
"resources": {
"limits": {
"cpu": "500m",
"memory": "512Mi"
}
}
}
]
}
}
}
}
}
Then update your work pool with this template:
bash
prefect work-pool create cloud-run-work-pool --type cloud-run --base-job-template job-template.json --overwrite
4. Make sure you have the necessary environment variables set:
bash
export PREFECT_API_KEY="your-api-key"
export PREFECT_API_URL="your-api-url"
Could you try these steps and let me know:
1. What version of prefect-gcp is installed after the upgrade?
2. Do you get the same error after recreating the work pool with the correct type and template?
3. Are you using any custom modifications to the job configuration in your deployments?
Also, please verify that your GCP service account has the necessary permissions:
- Cloud Run Developer (roles/run.developer
)
- Service Account User (roles/iam.serviceAccountUser
)
The error you're seeing typically occurs when the job template isn't properly structured with the required Kubernetes-style fields, but recreating the work pool with the correct type and template should resolve this.