Skip to content

Scheduler's CronSpec does not work with datetime.timezone offset #605

@matejscerba

Description

@matejscerba

Taskiq version

0.12.1

Python version

Python 3.13

OS

macOS

What happened?

When serializing and subsequently validating CronSpec with offset as datetime.timezone, the validated instance contains string representation of the offset, which is not valid:

>>> CronSpec.model_validate(CronSpec(offset=datetime.datetime.now().astimezone().tzinfo.utcoffset(None)).model_dump(mode="json"))
CronSpec(minutes='*', hours='*', days='*', months='*', weekdays='*', offset='PT2H')
>>> datetime.datetime.now().astimezone().tzinfo.utcoffset(None)
datetime.timedelta(seconds=7200)

Kicking the tasks uses .model_dump(mode="json"), which is what breaks the timezone-typed value.

Relevant log output

Broker initialization code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions