PrefectHQ / prefect

Prefect is a workflow orchestration framework for building resilient data pipelines in Python.
https://prefect.io
Apache License 2.0
16.01k stars 1.57k forks source link

Date Parameter invalid format when submitting flow run with custom parameters #6763

Closed benmton closed 2 years ago

benmton commented 2 years ago

First check

Bug summary

Submitting a flow run with custom datetime.date parameter causes a ParameterTypeError:

prefect.exceptions.ParameterTypeError: Flow run received invalid parameters:
 - date_param: invalid date format

Reproduction

I have a flow run like this:

@flow(name=flow_name)
def my_flow(date_param: dt.date = None):
    if date_param is None:
        date_str = dt.date.today().isoformat()
    else:
        date_str = date_param.isoformat()

and attempted to submit a run from the UI with a custom parameter like this: image First thing I notice is that the date format in the UI is in the US specific format rather than an international format. After submitting this run, I received this error in the flow run logs: image The parameter that is submitted to the flow is actually a datetime, and ends up being the wrong date as it assumes midnight in my local timezone before converting to UTC (I'm currently on UTC+1 timezone) image

Error

line 269, in validate_parameters
    raise ParameterTypeError.from_validation_error(exc) from None
prefect.exceptions.ParameterTypeError: Flow run received invalid parameters:
 - date_param: invalid date format

Browers

Prefect version

Version:             2.3.2
API version:         0.8.0
Python version:      3.9.13
Git commit:          6e931ee9
Built:               Tue, Sep 6, 2022 12:36 PM
OS/Arch:             linux/x86_64
Profile:             default
Server type:         hosted

Additional context

No response

zhen0 commented 2 years ago

Thanks for the feedback @benmton - this is a complex one! In part it's a partner to https://github.com/PrefectHQ/prefect/issues/6646 - another request for the ability to add a timezone to date time paramters in the UI.

But I think there's a also a bug related to how we're handling schema. @pleek91 - one to possibly test/be aware of with our schema updates

ceng-p commented 2 years ago

Hey, I'm also experiencing this, could it be parsed as a proper date string instead?In FastAPI for instance, if you select a parameter as datetime.date the string format becomes YYYY-MM-DD e.g 2002-02-02