Skip to content

Commit b0efdba

Browse files
committed
support passing optional date through CLI
Signed-off-by: Blake <[email protected]>
1 parent 5dae5a7 commit b0efdba

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

flytekit/interaction/click_types.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,17 @@ def convert(
558558
if isinstance(value, ArtifactQuery):
559559
return value
560560
try:
561+
# Handle datetime.date conversion for union types (e.g., Optional[datetime.date])
562+
target_type = self._python_type
563+
if hasattr(self._python_type, "__origin__") and self._python_type.__origin__ is typing.Union:
564+
# For union types like Optional[datetime.date], extract the non-None type
565+
union_args = typing.get_args(self._python_type)
566+
non_none_types = [arg for arg in union_args if arg is not type(None)]
567+
if len(non_none_types) == 1:
568+
target_type = non_none_types[0]
569+
561570
# If the expected Python type is datetime.date, adjust the value to date
562-
if self._python_type is datetime.date:
571+
if target_type is datetime.date:
563572
# Click produces datetime, so converting to date to avoid type mismatch error
564573
value = value.date()
565574
# If the input matches the default value in the launch plan, serialization can be skipped.

0 commit comments

Comments
 (0)