Running into an issue where I try edit the JSON of...
# prefect-cloud
j
Running into an issue where I try edit the JSON of a Custom Automation in Prefect Cloud but when I hit "Save & Exit" my changes aren't saved. Don't receive any JSON or Prefect errors as well.
a
Thanks @Jean Paul Azzopardi! I know this has been on @Craig Harshbarger and @collin's mind recently.
c
Hm I just tried reproducing by editing an existing automation trigger via the JSON view and saving worked for me. Would you be able to share any more information? i.e. • the trigger JSON you're working with • what change you're trying to make • a screenshot or screen recording
Don't receive any JSON or Prefect errors as well.
I'm curious what the UI looks like after attempting to "Save & Exit". There are some intended error states I'd expect to surface that could block you in this state but those should have accompanying UI - for example validation errors on invalid JSON.
j
The JSON I'm currently working with:
Copy code
{
  "type": "compound",
  "triggers": [
    {
      "type": "event",
      "match": {
        "prefect.resource.id": "prefect.flow-run.*"
      },
      "match_related": {
        "prefect.resource.id": [
          "prefect.tag.fifteen-minutes"
        ],
        "prefect.resource.role": "tag"
      },
      "after": [
        "prefect.flow-run.Running"
      ],
      "expect": [
        "prefect.flow-run.Completed"
      ],
      "for_each": [
        "prefect.resource.id"
      ],
      "posture": "Proactive",
      "threshold": 1,
      "within": 10
    },
    {
      "type": "event",
      "match": {},
      "match_related": {
        "prefect.resource.id": [
          "prefect.tag.daily"
        ],
        "prefect.resource.role": "tag"
      },
      "after": [
        "prefect.flow-run.Running"
      ],
      "expect": [
        "prefect.flow-run.Completed"
      ],
      "for_each": [
        "prefect.resource.id"
      ],
      "posture": "Proactive",
      "threshold": 1,
      "within": 108000
    },
    {
      "type": "event",
      "match": {},
      "match_related": {
        "prefect.resource.id": [
          "prefect.tag.hourly"
        ],
        "prefect.resource.role": "tag"
      },
      "after": [
        "prefect.flow-run.Running"
      ],
      "expect": [
        "prefect.flow-run.Completed"
      ],
      "for_each": [
        "prefect.resource.id"
      ],
      "posture": "Proactive",
      "threshold": 1,
      "within": 10800
    },
    {
      "type": "event",
      "match": {},
      "match_related": {
        "prefect.resource.id": [
          "prefect.tag.six-hours"
        ],
        "prefect.resource.role": "tag"
      },
      "after": [
        "prefect.flow-run.Running"
      ],
      "expect": [
        "prefect.flow-run.Completed"
      ],
      "for_each": [
        "prefect.resource.id"
      ],
      "posture": "Proactive",
      "threshold": 1,
      "within": 32400
    },
    {
      "type": "event",
      "match": {},
      "match_related": {
        "prefect.resource.id": [
          "prefect.tag.minute"
        ],
        "prefect.resource.role": "tag"
      },
      "after": [
        "prefect.flow-run.Running"
      ],
      "expect": [
        "prefect.flow-run.Completed"
      ],
      "for_each": [
        "prefect.resource.id"
      ],
      "posture": "Proactive",
      "threshold": 1,
      "within": 600
    },
    {
      "type": "event",
      "match": {},
      "match_related": {
        "prefect.resource.id": [
          "prefect.tag.weekly"
        ],
        "prefect.resource.role": "tag"
      },
      "after": [
        "prefect.flow-run.Running"
      ],
      "expect": [
        "prefect.flow-run.Completed"
      ],
      "for_each": [
        "prefect.resource.id"
      ],
      "posture": "Proactive",
      "threshold": 1,
      "within": 756000
    }
  ],
  "require": "any",
  "within": 0
}
What I'm trying to add :
Copy code
"actions": [
    {
      "type": "run-deployment",
      "source": "selected",
      "deployment_id": "...the uuid of the deployment...",
      "parameters": {"some_kwarg": "{{ event.resource.id }}"} 
    }
  ]
}
Screen recording:
c
Ah I see. An Automation has both triggers and actions, but a trigger does not directly have an action. This step of the wizard that you're on is for defining the _trigger_(s) for an automation - not a JSON representation of the entire automation. On the second step of that form, you can configure any actions you want your automation to execute once triggered. These docs detail what constitutes a trigger So what's happening here is you're adding in extraneous fields to this JSON input which get truncated and only the trigger-like JSON is kept. Let me know if this is still confusing and if there's anything else we can help clear up!
j
Got it. The reason I've been trying to configure actions in JSON is because I want to be able to have a compound trigger that returns details of the executed flow / deployment - but whenever I turn a single trigger with one event into a compound trigger with multiple events, that metadata is no longer there when sending a notification. For example, I have this trigger:
Copy code
{
  "type": "event",
  "match": {
    "prefect.resource.id": [
      "prefect.flow-run.*",
      "prefect.deployment.4ecda6e8-3b28-4146-aa6b-79eabe6a354d"
    ]
  },
  "match_related": {
    "prefect.resource.id": [
      "prefect.deployment.4ecda6e8-3b28-4146-aa6b-79eabe6a354d"
    ]
  },
  "after": [
    "prefect.flow-run.Running",
    "prefect.task-run.Running"
  ],
  "expect": [
    "prefect.flow-run.Completed"
  ],
  "for_each": [
    "prefect.resource.id"
  ],
  "posture": "Proactive",
  "threshold": 1,
  "within": 10
}
That returns event metadata. but when i turn it into a compound trigger, with another event...
Copy code
{
  "type": "compound",
  "triggers": [
    {
      "type": "event",
      "match": {
        "prefect.resource.id": [
          "prefect.flow-run.*",
          "prefect.deployment.4ecda6e8-3b28-4146-aa6b-79eabe6a354d"
        ]
      },
      "match_related": {
        "prefect.resource.id": [
          "prefect.deployment.4ecda6e8-3b28-4146-aa6b-79eabe6a354d"
        ]
      },
      "after": [
        "prefect.flow-run.Running"
      ],
      "expect": [
        "prefect.flow-run.Completed"
      ],
      "for_each": [
        "prefect.resource.id"
      ],
      "posture": "Proactive",
      "threshold": 1,
      "within": 10
    },
    {
      "type": "event",
      "match": {
        "prefect.resource.id": [
          "prefect.flow-run.*",
          "prefect.deployment.e3f116cb-2b34-43ce-9743-d71113c9f666"
        ]
      },
      "match_related": {
        "prefect.resource.id": [
          "prefect.deployment.e3f116cb-2b34-43ce-9743-d71113c9f666"
        ]
      },
      "after": [
        "prefect.flow-run.Running"
      ],
      "expect": [
        "prefect.flow-run.Completed"
      ],
      "for_each": [
        "prefect.resource.id"
      ],
      "posture": "Proactive",
      "threshold": 1,
      "within": 10
    }
  ],
  "require": "any",
  "within": 0
}
I no longer get event metadata when that trigger fires
c
For an automation with a composite type trigger, when the action is triggered, it could have multiple triggering events (for example, if you used
"require": "all"
). Therefore your notification action receives the triggering events under the variable
events
(notice the plural 's' at the end) in contrast to non-compound-type triggers which expose their triggering event under
event
. So I think you're looking for changing references from
event.<something>
->
events[0].<something>
when configuring your action. Or using Jinja, you should be able to use a block like
{% set event = events[0] %}
to require less tweaking. This could use better discoverability and/or compatibility like if we were to prepopulate event with events[0] which would at least make the use of
"require": "any"
here like you are doing more inline with using a non-compound trigger.
🙌 1
An issue to track docs improvements around this https://github.com/PrefectHQ/prefect/issues/14031
🙌 1