Samuel Hinton
02/23/2023, 2:06 AMfrom zoneinfo import ZoneInfo
from dateutil.rrule import MINUTELY, rrule
from prefect import flow
from prefect.deployments import Deployment
from prefect.server.schemas.schedules import RRuleSchedule
london = ZoneInfo("Europe/London")
@flow
def some_flow():
print("whoa")
Deployment.build_from_flow(
flow=some_flow,
schedule=RRuleSchedule.from_rrule(
rrule(
freq=MINUTELY,
interval=10,
dtstart=dt(2020, 1, 1, tzinfo=london),
byhour=range(8, 9),
)
),
)
Naively, I’d expect this to work, but it fails because ZoneInfo doesnt have a name attribute
schedule=RRuleSchedule.from_rrule(
File "/Users/sh/Projects/flows/.venv/lib/python3.9/site-packages/prefect/server/schemas/schedules.py", line 410, in from_rrule
timezone = rrule._dtstart.tzinfo.name
AttributeError: 'zoneinfo.ZoneInfo' object has no attribute 'name'
Theres an easy workaround here (like setting the timezone name explicitly like is done in schedules.py:413, but thought it might be good to get this working with pythons new standard way of handling timezones, especially because the old from datetime import timezone
requires specifying an hour delta which actually doesnt get used by prefect2