Requires version
0.8.93
or greater.condition_failed
.
An example condition
Take the following example:
morpheus
block returns a variable— pill
, which is either red or blue. Both downstream blocks have conditionals associated with them. The red_pill
block will only execute if pill
is red, and the blue_pill
block will only execute if pill
is blue.
Here’s what the conditionals look like for each:


pill=red
, the red_pill
block will execute, and the blue_pill
block will not. Additionally, any downstream blocks of the blue_pill
block will not execute.
Add conditionals to your pipeline
Conditional blocks are “add-on blocks” in Mage— that means they’re added through the side panel on the right in the pipeline editor.
- On the right side of the page, expand the side panel by hovering, click the Add-ons icon in the navigation.
- Click the button Conditionals.
- Click the button + Conditional block.
- In the conditional block’s code, add a function that returns a boolean value. Be sure it’s decorated with
@condition
. - Select the magnifiying class icon at the bottom of the block to associate your conditional with a block.
Positional arguments
The positional arguments to the conditional block will be the same as the positional arguments to the parent block. You can use the positional arguments to get the output of the upstream blocks.Keyword arguments
Here are the keyword arguments that are available in each conditional function:Name | Description | Sample value |
---|---|---|
block_uuid | Conditional block UUID. | 'fireball_conditional' |
ds | Date string when the parent block started executing. | '2023-12-25' |
event | A dictionary containing metadata from an event triggered pipeline. | {} |
execution_date | Python datetime object for when the trigger run started executing. | datetime.datetime(2023, 4, 26, 20, 28, 17, 335254, tzinfo=datetime.timezone.utc) |
execution_partition | Partition used for the trigger run when it was executed. | '207/20230426T202817' |
hr | Hour string when the trigger run started executing. | '20' |
pipeline_run | Python pipeline run object associated to the current run. | PipelineRun(id=2357, pipeline_uuid=fire_etl, execution_date=2023-04-26 20:28:17.335254+00:00) |
pipeline_uuid | UUID of the current pipeline. | 'fire_etl' |