cmarteepants opened a new pull request, #55093:
URL: https://github.com/apache/airflow/pull/55093
This PR enhances `HITLBranchOperator` to accept an optional
`options_mapping` dict that maps human-facing option labels to downstream
`task_ids`. Previously, HITL branching required users to select raw `task_ids`,
which isn’t user-friendly in business-facing workflows. With this change, a
workflow can present clearer options (e.g., “Full Deploy” / “Canary”) while
still resolving to valid downstream tasks.
**Changes**
- New parameter: options_mapping: dict[str, str] | None
- Keys: option labels (same as what's provided to `options`)
- Values: `task_ids` of valid downstream tasks
- Validation:
- Ensures keys are valid options
- Ensures values are strings (task_ids)
- Execution:
- Normalizes chosen options and applies mapping before branching
- Falls back to the raw option if no mapping is provided
- Tests:
- Single and multiple mapped choices
- Fallback to unmapped options
- Error when mapping points to non-downstream tasks (`AirflowException`)
- Error on invalid keys
- Error on non-string mapping values
**Rationale**
This improves HITL usability for end-users by decoupling the labels people
choose from the `task_ids` Airflow needs that may not necessarily be known by
the approver, while keeping strong validation in place.
Example
```
op = HITLBranchOperator(
task_id="choose",
subject="Approval required",
options=["Approve", "Reject"],
options_mapping={"Approve": "publish", "Reject": "archive"},
)
op >> [EmptyOperator(task_id="publish"), EmptyOperator(task_id="archive")]
```
If the user selects Approve, the operator branches to the `publish` task.
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]