-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(client): allow non-numeric run/task IDs for Argo and Step Functions #3260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |||||
|
|
||||||
| import json | ||||||
| import os | ||||||
| import re | ||||||
| import tarfile | ||||||
| from collections import namedtuple | ||||||
| from datetime import datetime | ||||||
|
|
@@ -60,6 +61,13 @@ | |||||
|
|
||||||
| current_metadata = False | ||||||
|
|
||||||
| # Run IDs can be plain integers (local runs) or prefixed strings for orchestrators: | ||||||
| # "argo-<workflow-name>" for Argo Workflows | ||||||
| # "sfn-<execution-name>" for AWS Step Functions | ||||||
| # Task IDs follow the same pattern — numeric by default but may be prefixed by | ||||||
| # orchestrators that pass their own identifiers. | ||||||
| _RUN_ID_PATTERN = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9\-_]*$') | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||
|
|
||||||
|
|
||||||
| def metadata(ms: str) -> str: | ||||||
| """ | ||||||
|
|
@@ -336,6 +344,24 @@ def __init__( | |||||
| "Expects DataArtifact('FlowName/RunID/StepName/TaskID/ArtifactName')" | ||||||
| ) | ||||||
|
|
||||||
| # Validate run ID and task ID format. | ||||||
| # Run IDs are numeric for local runs but orchestrators (Argo Workflows, | ||||||
| # AWS Step Functions) produce prefixed string IDs like "argo-*" and "sfn-*". | ||||||
| # The same applies to task IDs. | ||||||
| if len(ids) >= 2 and not _RUN_ID_PATTERN.match(ids[1]): | ||||||
| raise MetaflowInvalidPathspec( | ||||||
| "Invalid run ID '%s' in pathspec '%s'. " | ||||||
| "Run IDs must be alphanumeric and may contain hyphens or " | ||||||
| "underscores (e.g. '123', 'argo-myflow-abc12', 'sfn-exec')." | ||||||
| % (ids[1], pathspec) | ||||||
| ) | ||||||
| if len(ids) >= 4 and not _RUN_ID_PATTERN.match(ids[3]): | ||||||
| raise MetaflowInvalidPathspec( | ||||||
| "Invalid task ID '%s' in pathspec '%s'. " | ||||||
| "Task IDs must be alphanumeric and may contain hyphens or underscores." | ||||||
| % (ids[3], pathspec) | ||||||
| ) | ||||||
|
|
||||||
| self.id = ids[-1] | ||||||
| self._pathspec = pathspec | ||||||
| self._object = self._get_object(*ids) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWS Step Functions execution names can legally contain
.(and other characters like+,@) per the SFNStartExecutionAPI. When a state machine is triggered externally — e.g. by an EventBridge rule with a custom execution name such asprod.2024-01-15— the run ID stored by Metaflow issfn-prod.2024-01-15. After this PR, anyRun('MyFlow/sfn-prod.2024-01-15')call will raiseMetaflowInvalidPathspec, whereas before this PR (where no content validation existed) it would look up the run normally. The original code's correctness guarantee was "only check component count" — this pattern narrows that guarantee without covering the full character set that SFN execution names allow.