Skip to content

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

Closed

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

Activity

  1. s3rius commented on Apr 10, 2026

    @s3rius
    Member

    It seems like a pydantic bug, actually. I'd not expect it to be serialized to such a weird value, actually. I'm not even sure what PT{n}H means.

    But I agree that actually it's quite unexpected.

    Here's a pydantic issue:
    pydantic/pydantic#7095

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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