prefect.server.api.validation

This module contains functions for validating job variables for deployments, work pools, flow runs, and RunDeployment actions. These functions are used to validate that job variables provided by users conform to the JSON schema defined in the work pool’s base job template.

Note some important details:

  1. The order of applying job variables is: work pool’s base job template, deployment, flow run. This means that flow run job variables override deployment job variables, which override work pool job variables.

  2. The validation of job variables for work pools and deployments ignores required keys in because we don’t know if the full set of overrides will include values for any required fields.

  3. Work pools can include default values for job variables. These can be normal types or references to blocks. We have not been validating these values or whether default blocks satisfy job variable JSON schemas. To avoid failing validation for existing (otherwise working) data, we ignore invalid defaults when validating deployment and flow run variables, but not when validating the work pool’s base template, e.g. during work pool creation or updates. If we find defaults that are invalid, we have to ignore required fields when we run the full validation.

  4. A flow run is the terminal point for job variables, so it is the only place where we validate required variables and default values. Thus, validate_job_variables_for_deployment_flow_run and validate_job_variables_for_run_deployment_action check for required fields.

  5. We have been using Pydantic v1 to generate work pool base job templates, and it produces invalid JSON schemas for some fields, e.g. tuples and optional fields. We try to fix these schemas on the fly while validating job variables, but there is a case we can’t resolve, which is whether or not an optional field supports a None value. In this case, we allow None values to be passed in, which means that if an optional field does not actually allow None values, the Pydantic model will fail to validate at runtime.