Validate Dag and task IDs in the Go SDK#69965
Conversation
The Go SDK accepted any string as a Dag or task ID, while the Python task-sdk (validate_key), the ts-sdk (apache#69400), and the Java SDK reject IDs that are empty, longer than 250 characters, or contain characters outside Unicode letters, digits, dashes, dots, and underscores. Aligning the rule across SDKs makes an invalid ID fail fast at registration with a clear error instead of a silent lookup miss later.
|
PR description says "Adds the same validation to the Java SDK". |
You’re right, already fixed it. Thanks! |
The existing valid-id tests use only ASCII, where byte and rune counts match, so they would still pass if the length check regressed from RuneCountInString to len — silently rejecting a valid 250-character non-ASCII id that occupies 750 bytes. Add a 250-rune multibyte id to the Dag and Task accept tests so a valid non-ASCII id stays valid.
1ce3197 to
d2b2962
Compare
There was a problem hiding this comment.
LGTM overall, thanks.
UPDATE:
As mentioned in #69937 (review), we will need to wait for the coordinator side first.
|
|
||
| const maxKeyLength = 250 | ||
|
|
||
| var keyRegex = regexp.MustCompile(`^[\p{L}\p{N}_.-]+$`) |
There was a problem hiding this comment.
IIUC, the a..b case can pass the validation. Perhaps it's worthwhile to add the unit test to exercise. Thanks.
airflow/airflow-core/src/airflow/serialization/definitions/dag.py
Lines 637 to 648 in ffde962
| fnName := getFnName(val) | ||
|
|
There was a problem hiding this comment.
We should also validate the AddTask call here. Since we will pass the generic function name itself as the taskID name.
Validate Dag and task IDs in the Go SDK
Why
Go SDK currently accepts any string as Dag/task ID. Python SDK already validates this with validate_key (max 250 chars, only letters, digits, -, ., _), and ts-sdk added the same check in #69400.
What
Adds the same validation to the Go SDK, so invalid IDs fail early at registration.
related: #69400, #69937
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code Opus 4.8 following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.