-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support rendering tasks with non-ASCII characters (#1278)
## Description When running models that have names containing multibyte characters, runtime errors occur in Airflow environments where statsd is enabled (e.g., MWAA uses this statsd metric for collecting metrics in Cloudwatch). Related Issue: apache/airflow#18010 To address this, Airflow 2.9 introduced the ability to render tasks using display_name, which allows task names to be rendered separately from their task_id. Reference: https://airflow.apache.org/docs/apache-airflow/stable/_modules/airflow/example_dags/example_display_name.html This PR adds support for display_name, enabling users who use non-ASCII characters as their native language to display task names in their own language, even in environments like MWAA. ### Details The normalize_task_id parameter is added to RenderConfig. This option accepts a function to generate a task ID from a node. This allows users to generate arbitrary task IDs from models. If a function is passed to this option, Cosmos will use the model name as the display_name for tasks while rendering them. ```python def normalize_task_id(node): """ This function takes a node and returns a new task_id. """ if node.name == "MULTIBYTE_MODEL_NAME": return "MULTIBYTE_MODEL_NAME" render_config = RenderConfig( normalize_task_id=normalize_task_id ) ``` ## Related Issue(s) closes #1277 ## Breaking Change? <!-- If this introduces a breaking change, specify that here. --> ## Checklist - [x] I have made corresponding changes to the documentation (if required) - [x] I have added tests that prove my fix is effective or that my feature works --------- Co-authored-by: Pankaj Singh <[email protected]>
- Loading branch information
1 parent
3eb9b98
commit ea67123
Showing
6 changed files
with
193 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.. _task-display-name: | ||
|
||
Task display name | ||
================ | ||
|
||
.. note:: | ||
This feature is only available for Airflow >= 2.9. | ||
|
||
In Airflow, ``task_id`` does not support non-ASCII characters. Therefore, if users wish to use non-ASCII characters (such as their native language) as display names while keeping ``task_id`` in ASCII, they can use the ``display_name`` parameter. | ||
|
||
To work with projects that use non-ASCII characters in model names, the ``normalize_task_id`` field of ``RenderConfig`` can be utilized. | ||
|
||
Example: | ||
|
||
You can provide a function to convert the model name to an ASCII-compatible format. The function’s output is used as the TaskID, while the display name on Airflow remains as the original model name. | ||
|
||
.. code-block:: python | ||
from slugify import slugify | ||
def normalize_task_id(node): | ||
return slugify(node.name) | ||
from cosmos import DbtTaskGroup, RenderConfig | ||
jaffle_shop = DbtTaskGroup( | ||
render_config=RenderConfig(normalize_task_id=normalize_task_id) | ||
) | ||
.. note:: | ||
Although the slugify example often works, it may not be suitable for use in actual production. Since slugify performs conversions based on pronunciation, there may be cases where task_id is not unique due to homophones and similar issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters