Skip to content

Added support for Enum types in Pydantic models#3391

Open
AdilFayyaz wants to merge 2 commits intomasterfrom
adil/fix-type-enum-v1
Open

Added support for Enum types in Pydantic models#3391
AdilFayyaz wants to merge 2 commits intomasterfrom
adil/fix-type-enum-v1

Conversation

@AdilFayyaz
Copy link
Collaborator

Tracking issue

Duplicated from: flyteorg/flyte-sdk/pull/622

Why are the changes needed?

Ensure flytekit versions alongside flytesdk

What changes were proposed in this pull request?

In generate_attribute_list_from_dataclass_json_mixin(), when a $ref resolves to an enum definition (has enum key, no properties), map the field to str instead of trying to construct a dataclass from it. Previously this crashed with KeyError: 'properties' because the code assumed every $ref pointed to a model.

How was this patch tested?

Test (test_enum_in_pydantic.py): Defines a Job(BaseModel) with a Status(str, Enum) field, roundtrips it through to_literal_type -> to_literal -> to_python_value -> guess_python_type, and verifies the guessed dataclass accepts enum values as strings.

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Signed-off-by: M. Adil Fayyaz <62440954+AdilFayyaz@users.noreply.github.com>
Signed-off-by: M. Adil Fayyaz <62440954+AdilFayyaz@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.80%. Comparing base (ba7dc6f) to head (83826a5).

Files with missing lines Patch % Lines
flytekit/core/type_engine.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #3391       +/-   ##
===========================================
- Coverage   95.82%   47.80%   -48.02%     
===========================================
  Files           5      216      +211     
  Lines         527    22782    +22255     
  Branches        0     2998     +2998     
===========================================
+ Hits          505    10892    +10387     
- Misses         22    11295    +11273     
- Partials        0      595      +595     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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