-
Notifications
You must be signed in to change notification settings - Fork 299
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
[fix] Validate interface variable names are python-valid #2538
[fix] Validate interface variable names are python-valid #2538
Conversation
cc4d830
to
631dc40
Compare
flytekit/core/interface.py
Outdated
if not k.isidentifier(): | ||
raise ValueError(f'Input must be valid Python identifier: {k!r}') |
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.
Adds validation on input naming in Interface
. Note that this is already done on the outputs:
variables = [k for k in outputs.keys()]
...
collections.namedtuple(..., variables) # collections.namedtuple checks
# the variable names are valid python identifiers
So it is sensible to add similar validation to the inputs, which must also by valid python types.
@@ -70,6 +71,8 @@ def __init__( | |||
self._inputs: Union[Dict[str, Tuple[Type, Any]], Dict[str, Type]] = {} # type: ignore | |||
if inputs: | |||
for k, v in inputs.items(): | |||
if not k.isidentifier(): |
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.
Nice. I was about to mention isidentifier
. 😄
with pytest.raises(ValueError, match=r"Input must be valid Python identifier:"): | ||
_ = Interface({"my.input": int}, {}) | ||
|
||
with pytest.raises(ValueError, match=r"Type names and field names must be valid identifiers:"): |
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.
The error message is odd here, but it is the standard error message from collections.namedtuple
see: https://github.com/flyteorg/flytekit/pull/2538/files#r1657915913 https://github.com/python/cpython/blob/main/Lib/collections/__init__.py#L401-L402
Signed-off-by: ddl-rliu <[email protected]>
631dc40
to
bb0f43d
Compare
@ddl-rliu , can you fix the lint error in CI? You can run |
Signed-off-by: ddl-rliu <[email protected]>
8c476c9
to
8240ea2
Compare
Signed-off-by: ddl-rliu <[email protected]>
@eapolinario done! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2538 +/- ##
===========================================
- Coverage 91.30% 72.40% -18.91%
===========================================
Files 78 182 +104
Lines 3968 18576 +14608
Branches 0 3659 +3659
===========================================
+ Hits 3623 13450 +9827
- Misses 345 4479 +4134
- Partials 0 647 +647 ☔ View full report in Codecov by Sentry. |
* Validate interface variable names Signed-off-by: ddl-rliu <[email protected]> * Remove unused import Signed-off-by: ddl-rliu <[email protected]> * Fix lint error Signed-off-by: ddl-rliu <[email protected]> --------- Signed-off-by: ddl-rliu <[email protected]> Signed-off-by: bugra.gedik <[email protected]>
* Validate interface variable names Signed-off-by: ddl-rliu <[email protected]> * Remove unused import Signed-off-by: ddl-rliu <[email protected]> * Fix lint error Signed-off-by: ddl-rliu <[email protected]> --------- Signed-off-by: ddl-rliu <[email protected]> Signed-off-by: Jan Fiedler <[email protected]>
* Validate interface variable names Signed-off-by: ddl-rliu <[email protected]> * Remove unused import Signed-off-by: ddl-rliu <[email protected]> * Fix lint error Signed-off-by: ddl-rliu <[email protected]> --------- Signed-off-by: ddl-rliu <[email protected]> Signed-off-by: mao3267 <[email protected]>
Tracking issue
flyteorg/flyte#5511
Why are the changes needed?
Rationale: flyte inputs names are "like" python variable names, which should not use special characters like . (see my.value in the repro code
Expected behavior: The workflow should actually fail at compile time at step 1. (e.g. perform extra validation)
What changes were proposed in this pull request?
Workflow should fail at compile time at step 1, when python-invalid variable name is used like "my.value".
How was this patch tested?
Setup process
Screenshots
Check all the applicable boxes
Related PRs
Docs link