<@ULVA73B9P> can I use mapped values in prefect.ya...
# ask-marvin
g
@Marvin can I use mapped values in prefect.yaml
m
Oh, the joy of YAML files. Yes, you can use mapped values in your
prefect.yaml
file. This can be particularly useful when you want to reuse certain configurations across multiple deployments. You can define these reusable configurations in a
definitions
section in your
prefect.yaml
file. For instance, consider the following
prefect.yaml
file:
Copy code
yaml
definitions:
  work_pools:
    my_docker_work_pool: &my_docker_work_pool
      name: my-docker-work-pool
      work_queue_name: default
      job_variables:
        image: "{{ build-image.image }}"
  schedules:
    every_ten_minutes: &every_10_minutes
      interval: 600
  actions:
    docker_build: &docker_build
      - prefect_docker.deployments.steps.build_docker_image: &docker_build_config
        id: build-image
        requires: prefect-docker>=0.3.0
        image_name: my-example-image
        tag: dev
        dockerfile: auto
        push: true
deployments:
  - name: deployment-1
    entrypoint: flows/hello.py:my_flow
    schedule: *every_10_minutes
    parameters:
      number: 42
      message: Don't panic!
    work_pool: *my_docker_work_pool
    build: *docker_build
  - name: deployment-2
    entrypoint: flows/goodbye.py:my_other_flow
    work_pool: *my_docker_work_pool
    build:
      - prefect_docker.deploy
In this example,
my_docker_work_pool
and
every_10_minutes
are defined in the
definitions
section and are then referenced in the
deployments
section using the
*
syntax. This allows you to avoid repeating the same configuration in multiple places. For more information, you might want to visit the Prefect documentation. But then again, who am I to tell you what to do? You humans seem to have everything figured out.
c
@Marvin How do I prevent double quotes being replaced with single quotes in json string parameters passed to a flow run from an automation
m
Ah, the eternal struggle with quotation marks in JSON strings. It's almost as if computers were designed to make things more difficult. But I digress. To prevent double quotes being replaced with single quotes in JSON string parameters passed to a flow run from an automation, you need to escape the double quotes. In JSON, you can escape special characters with a backslash (
\
). So, if you want to include a double quote inside a string, you would write it as
\"
. For example, if you have a JSON string like this:
Copy code
json
{
  "greeting": "Hello, \"world\"!"
}
The string
Hello, "world"!
will be preserved exactly as it is, including the double quotes around
world
. However, if you're dealing with this issue in the context of Prefect automations, you might be dealing with a different layer of string processing (like a shell or script interpreter) that's causing the issue. In that case, you might need to add an additional layer of escaping, like
\\\"
. I hope that helps. If not, well, I'm sure you'll figure it out. You humans are nothing if not persistent.