Skip to content

Conversation

blaketastic2
Copy link
Contributor

@blaketastic2 blaketastic2 commented Jun 11, 2025

Why are the changes needed?

Currently, if we have a workflow with an optional date parameter, we cannot call this from the CLI.

Workflow definition:

@workflow
def ingest_data(
    start_date: Optional[date] = None,
) -> None:
    pass

Executing the workflow:

pyflyte run --copy all -p flyte-snacks -d development --remote workflow.py ingest_data --start_date 2025-06-10

Produces this error:

Invalid value for '--start_date': Failed to convert param: <Option start_date>, value: 2025-06-10 00:00:00 to type: typing.Optional[datetime.date]. Reason
Cannot convert from 2025-06-10 00:00:00 to typing.Optional[datetime.date]

What changes were proposed in this pull request?

We are now making sure to use the non-None variant when trying to do the conversion.

Summary by Bito

This pull request enhances the CLI's handling of optional date parameters by improving type conversion, specifically addressing datetime to optional date type conversions to prevent type mismatch errors. These enhancements aim to improve user experience in workflows requiring date parameters.

Copy link

codecov bot commented Jun 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.85%. Comparing base (3c6b61d) to head (199c8fe).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3273      +/-   ##
==========================================
+ Coverage   83.35%   92.85%   +9.50%     
==========================================
  Files         347       18     -329     
  Lines       28791      812   -27979     
  Branches     2960        0    -2960     
==========================================
- Hits        23999      754   -23245     
+ Misses       3956       58    -3898     
+ Partials      836        0     -836     

☔ 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.

@kumare3
Copy link
Contributor

kumare3 commented Jun 11, 2025

I think it should be here -

@blaketastic2
Copy link
Contributor Author

@kumare3 Alright, what do you think about this approach?

@blaketastic2
Copy link
Contributor Author

I'm hoping we can move forward with this

Comment on lines 588 to 572
if self._python_type is datetime.date and isinstance(value, datetime.datetime):
# Click produces datetime, so converting to date to avoid type mismatch error
value = value.date()
Copy link
Member

@machichima machichima Jul 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just modify here and do not need to add a new DateType. While it already deal with the conversion for datetime.date type, what we need to do is to also trigger this conversion for Optional[datetime.date] and datetime.date | None type.

The following should work:

            is_union = typing.get_origin(self._python_type) in (typing.Union, types.UnionType)
            args = typing.get_args(self._python_type)
            is_date_type = (
                (is_union and datetime.date in args)
                or self._python_type is datetime.date
            )

            if is_date_type and isinstance(value, datetime.datetime):
                value = value.date()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that's fair. I've made the change, so hopefully we can get this merged in soon.

@blaketastic2 blaketastic2 force-pushed the support-providing-optional-param-cli branch 2 times, most recently from 1757a6e to 79939f4 Compare August 4, 2025 15:19
@blaketastic2 blaketastic2 force-pushed the support-providing-optional-param-cli branch from 79939f4 to 07981f1 Compare August 4, 2025 15:26
@machichima
Copy link
Member

@blaketastic2 Could you fix CI failure? Thanks!

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.

3 participants