Skip to content

fix: EnumTransformer.to_literal accepts a string matching an enum value#3439

Open
1fanwang wants to merge 1 commit into
flyteorg:masterfrom
1fanwang:enum-to-literal-accepts-string
Open

fix: EnumTransformer.to_literal accepts a string matching an enum value#3439
1fanwang wants to merge 1 commit into
flyteorg:masterfrom
1fanwang:enum-to-literal-accepts-string

Conversation

@1fanwang

Copy link
Copy Markdown
Contributor

Why are the changes needed?

EnumTransformer.assert_type accepts a raw string that matches one of the enum's values (e.g. an enum default supplied as a string in an execution/launch config). EnumTransformer.to_literal rejects that same string with Expected an enum. So a matching-string enum value passes type-checking and then fails at serialization — an inconsistency between the two methods.

What changes were proposed in this pull request?

EnumTransformer.to_literal now accepts a string that matches one of the enum's values, serializing it to the corresponding string literal — consistent with assert_type. A non-matching string is still rejected.

How was this patch tested?

Added test_enum_to_literal_accepts_matching_string.

pytest tests/flytekit/unit/core/test_type_engine.py -k test_enum_to_literal_accepts_matching_string

Before:

>       raise TypeTransformerFailedError("Expected an enum")
E       flytekit.core.type_engine.TypeTransformerFailedError: Expected an enum
FAILED tests/flytekit/unit/core/test_type_engine.py::test_enum_to_literal_accepts_matching_string

After:

1 passed

Check all the applicable boxes

  • All new and existing tests passed.
  • All commits are signed-off.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant