PrefectHQ / prefect

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

Date Picker Issue in UI When Using datetime.now() Without Timezone #14002

Open EmilRex opened 3 weeks ago

EmilRex commented 3 weeks ago

First check

Bug summary

I am encountering an issue with the date picker in the UI when submitting a run. The flow takes two datetime inputs, but it doesn't seem to work correctly with the date picker when using datetime.now() without a timezone.

Reproduction

from datetime import datetime, timedelta
from prefect import flow

@flow(retries=2)
def backfill(
    since: datetime = (datetime.now() - timedelta(days=20)),
    until: datetime = datetime.now(),
):
    print(f"Running backfill from {since} to {until}")

if __name__ == "__main__":
    backfill.serve()

Error

N/A (Issue is with date picker validation)

Versions

Version:             2.19.4
API version:         0.8.4
Python version:      3.9.19
Git commit:          867543a8
Built:               Tue, Jun 4, 2024 3:14 PM
OS/Arch:             darwin/arm64
Profile:             sandbox
Server type:         cloud

Additional context

The issue seems to be related to datetime.now() not having a timezone. Below is an updated version of the flow that works fine:

from datetime import UTC, datetime, timedelta
from prefect import flow

@flow(log_prints=True)
def backfill(
    since: datetime = (datetime.now(UTC) - timedelta(days=20)),
    until: datetime = datetime.now(UTC),
):
    print(f"Running backfill from {since} to {until}")

if __name__ == "__main__":
    backfill.serve()

The UI's date picker and the schema's datetime formats are not aligning properly, leading to validation errors.

zhen0 commented 3 weeks ago

Thanks Emil. We plan to address this as part of a more holistic look at how we handle any default value that doesn’t pass validation.