https://prefect.io logo
Title
k

Kevin Weiler

06/29/2020, 9:42 PM
is this error expected?
TypeError: Object of type datetime is not JSON serializable
the relevant code is, outside the flow context:
@task(result=PrefectResult())
def assert_db_trigger(event_name: str, events_fetcher: DailyFlowEvents, point_date: datetime):
    events = events_fetcher.fetch_events()
    while event_name not in events.keys() or events[event_name] < point_date:
        print(f"No trigger, yet for {event_name}")
        sleep(5)
        events = events_fetcher.fetch_events()
    return point_date
and
point_datetime = datetime(year=point_date.year, month=point_date.month, day=point_date.day, hour=0, minute=0, second=0, microsecond=0, tzinfo=pytz.UTC)
and within the flow context:
task_wait_for_reference_data_validated = assert_db_trigger("reference_data_validated", daily_flow_events, point_datetime)
do all function/method arguments need to be JSON serializable?
k

Kyle Moon-Wright

06/29/2020, 9:53 PM
Hey @Kevin Weiler, This is correct, Prefect uses
cloudpickle
to serialize payloads between tasks to adhere to the Hybrid Model. Looks like your
datetime
object is causing this error to occur?
k

Kevin Weiler

06/29/2020, 9:54 PM
I think so - probably not a big deal, can construct this within the task most likely