Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redbeat do not support ZoneInfo classes (PEP-615) #219

Closed
Cediddi opened this issue Jul 4, 2022 · 1 comment
Closed

Redbeat do not support ZoneInfo classes (PEP-615) #219

Cediddi opened this issue Jul 4, 2022 · 1 comment

Comments

@Cediddi
Copy link

Cediddi commented Jul 4, 2022

PEP-615 defines a ZoneInfo class which kind of deprecates pytz in the long term.

The code below is not tied to any django project, thus timezone defined should be the default value, UTC.

Pytz works, thus I'll be using it for the foreseeable future.

Here's the code related to this issue:

from zoneinfo import ZoneInfo

def now_in_germany():
    return datetime.datetime.now(tz=ZoneInfo('Europe/Berlin'))


crontab_germany = partial(crontab, nowfun=now_in_germany)

BEAT_SCHEDULE = {
    "every-minute": {
        "task": "<something>",
        "schedule": crontab_germany("*", "7,13", "*", "*", "*", ),
        # 7AM and 1PM in german time
        "args": (),
    },
}

Here's the traceback:

beat raised exception <class 'AttributeError'>: AttributeError("'zoneinfo.ZoneInfo' object has no attribute 'zone'")
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/celery/apps/beat.py", line 105, in start_scheduler
    service.start()
  File "/usr/local/lib/python3.10/site-packages/celery/beat.py", line 636, in start
    humanize_seconds(self.scheduler.max_interval))
  File "/usr/local/lib/python3.10/site-packages/kombu/utils/objects.py", line 30, in __get__
    return super().__get__(instance, owner)
  File "/usr/local/lib/python3.10/functools.py", line 981, in __get__
    val = self.func(instance)
  File "/usr/local/lib/python3.10/site-packages/celery/beat.py", line 679, in scheduler
    return self.get_scheduler()
  File "/usr/local/lib/python3.10/site-packages/celery/beat.py", line 670, in get_scheduler
    return symbol_by_name(self.scheduler_cls, aliases=aliases)(
  File "/usr/local/lib/python3.10/site-packages/redbeat/schedulers.py", line 377, in __init__
    super(RedBeatScheduler, self).__init__(app, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/celery/beat.py", line 271, in __init__
    self.setup_schedule()
  File "/usr/local/lib/python3.10/site-packages/redbeat/schedulers.py", line 395, in setup_schedule
    self.update_from_dict(self.app.redbeat_conf.schedule)
  File "/usr/local/lib/python3.10/site-packages/redbeat/schedulers.py", line 409, in update_from_dict
    entry.save()  # store into redis
  File "/usr/local/lib/python3.10/site-packages/redbeat/schedulers.py", line 306, in save
    pipe.hsetnx(self.key, 'meta', json.dumps(meta, cls=RedBeatJSONEncoder))
  File "/usr/local/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/local/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/lib/python3.10/site-packages/redbeat/decoder.py", line 79, in default
    elif obj.tzinfo.zone is None:
AttributeError: 'zoneinfo.ZoneInfo' object has no attribute 'zone'
@sibson
Copy link
Owner

sibson commented May 19, 2023

I believe #245 fixes this. Feel free to re-open if not.

@sibson sibson closed this as completed May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants