Skip to content
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

[Schedule] Update type hints for ScheduleCronTrigger to avoid unexpected pydantic behaviour #3286

Merged
merged 1 commit into from Mar 22, 2023

Conversation

Eyal-Danieli
Copy link
Member

When defining type hints for pydantic objects with typing.Union, pydantic will attempt to match any of the types defined under typing.Union and will use the first one that matches.
However, when adding typing.Optional (e.g. Optional[Union[datetime, str]]) the user may face unexpected behaviour in which the order within the Union has been changed and pydantic will match the wrong type (e.g. trying to match str before datetime although datetime is the first type in the Union list). This bug occurs following different imports of 3rd libraries. More info about this pydantic behaviour can be found here: pydantic/pydantic#4474
pydantic/pydantic#4519

To avoid this unexpected behaviour, in this PR we replace typing.Optional with default None value for the fields start_date and end_date within ScheduleCronTrigger object.

Pleas note that new tests are not required as this behaviour is already being tested through test_update_schedule().

A related JIRA ticket - https://jira.iguazeng.com/browse/ML-3624

@assaf758 assaf758 merged commit c8371e5 into mlrun:development Mar 22, 2023
14 checks passed
assaf758 pushed a commit to assaf758/mlrun that referenced this pull request Mar 22, 2023
Eyal-Danieli added a commit to Eyal-Danieli/mlrun that referenced this pull request Mar 22, 2023
assaf758 added a commit that referenced this pull request Mar 22, 2023
yaelgen pushed a commit to yaelgen/mlrun that referenced this pull request Apr 24, 2023
@Eyal-Danieli Eyal-Danieli deleted the scheudle-cron-fix branch June 25, 2023 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants