Skip to content

Commit c93a1c5

Browse files
authored
support passing optional date through CLI (#3273)
* support passing optional date through CLI Signed-off-by: Blake <[email protected]> * feedback from review Signed-off-by: Blake <[email protected]> * feedback from review Signed-off-by: Blake <[email protected]> --------- Signed-off-by: Blake <[email protected]>
1 parent 57db1e8 commit c93a1c5

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

flytekit/interaction/click_types.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import pathlib
1010
import sys
11+
import types
1112
import typing
1213
import typing as t
1314
from typing import cast, get_args
@@ -561,7 +562,14 @@ def convert(
561562
return value
562563
try:
563564
# If the expected Python type is datetime.date, adjust the value to date
564-
if self._python_type is datetime.date:
565+
is_union = typing.get_origin(self._python_type) in (
566+
typing.Union,
567+
types.UnionType,
568+
)
569+
args = typing.get_args(self._python_type)
570+
is_date_type = (is_union and datetime.date in args) or self._python_type is datetime.date
571+
572+
if is_date_type and isinstance(value, datetime.datetime):
565573
# Click produces datetime, so converting to date to avoid type mismatch error
566574
value = value.date()
567575
# If the input matches the default value in the launch plan, serialization can be skipped.

0 commit comments

Comments
 (0)