Skip to content

Validate Dag and task IDs in the Go SDK#69965

Open
Andrushika wants to merge 2 commits into
apache:mainfrom
Andrushika:go-sdk-validate-ids
Open

Validate Dag and task IDs in the Go SDK#69965
Andrushika wants to merge 2 commits into
apache:mainfrom
Andrushika:go-sdk-validate-ids

Conversation

@Andrushika

@Andrushika Andrushika commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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?
  • Yes (please specify the tool below)

Generated-by: Claude Code Opus 4.8 following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {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.

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.
Comment thread go-sdk/bundle/bundlev1/registry_test.go
@viiccwen

Copy link
Copy Markdown
Contributor

PR description says "Adds the same validation to the Java SDK".
It's Go SDK, right?

@Andrushika

Copy link
Copy Markdown
Contributor Author

PR description says "Adds the same validation to the Java SDK". It's Go SDK, right?

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.
@Andrushika
Andrushika force-pushed the go-sdk-validate-ids branch from 1ce3197 to d2b2962 Compare July 16, 2026 17:50

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}_.-]+$`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the a..b case can pass the validation. Perhaps it's worthwhile to add the unit test to exercise. Thanks.

if ".." in run_id and not airflow_conf.getboolean("core", "allow_double_dot_in_ids", fallback=False):
raise ValueError(f"The run_id '{run_id}' must not contain '..' to prevent path traversal")
# This is also done on the DagRun model class, but SQLAlchemy column
# validator does not work well for some reason.
if not re.match(RUN_ID_REGEX, run_id):
regex = airflow_conf.get("scheduler", "allowed_run_id_pattern").strip()
if not regex or not re.match(regex, run_id):
raise ValueError(
f"The run_id provided '{run_id}' does not match regex pattern "
f"'{regex}' or '{RUN_ID_REGEX}'"
)

Comment on lines 183 to 184
fnName := getFnName(val)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also validate the AddTask call here. Since we will pass the generic function name itself as the taskID name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants