'int' object has no attribute 'days' when registering flow

This works when running locally:

import datetime

import pandas as pd
from prefect import Flow


@task(
    cache_for=datetime.timedelta(days=365),
    max_retries=3,
    retry_delay=60
)
def get_us_states():
    states_df = pd.read_csv(US_STATES_URL)
    states = states_df["Abbreviation"].tolist()
    return states


with Flow("weather_record") as flow:
    states = get_us_states()


flow.run()

However, when it’s registered…

import datetime

import pandas as pd
from prefect import Flow


@task(
    cache_for=datetime.timedelta(days=365),
    max_retries=3,
    retry_delay=60
)
def get_us_states():
    states_df = pd.read_csv(US_STATES_URL)
    states = states_df["Abbreviation"].tolist()
    return states


with Flow("weather_record") as flow:
    states = get_us_states()


flow.register("weather")

It results in an error.

File ~/mambaforge/envs/prefect-v1/lib/python3.10/site-packages/marshmallow/utils.py:337, in timedelta_to_microseconds(value)
    332 def timedelta_to_microseconds(value: dt.timedelta) -> int:
    333     """Compute the total microseconds of a timedelta
    334 
    335     https://github.com/python/cpython/blob/bb3e0c240bc60fe08d332ff5955d54197f79751c/Lib/datetime.py#L665-L667  # noqa: B950
    336     """
--> 337     return (value.days * (24 * 3600) + value.seconds) * 1000000 + value.microseconds

AttributeError: 'int' object has no attribute 'days'
1 Like

The fix is to convert retry_delay to timedelta.

import datetime

import pandas as pd
from prefect import Flow


@task(
    cache_for=datetime.timedelta(days=365),
    max_retries=3,
    retry_delay=datetime.timedelta(seconds=60)
)
def get_us_states():
    states_df = pd.read_csv(US_STATES_URL)
    states = states_df["Abbreviation"].tolist()
    return states


with Flow("weather_record") as flow:
    states = get_us_states()


flow.register("weather")
1 Like