Skip to content

Celery no longer honoring Django's TIME_ZONE setting #4006

Closed

Description

@izquierdo

http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html states:

For Django users the time zone specified in the TIME_ZONE setting will be used

This used to be true (checked in Celery 3.1.25) but is no longer the case in Celery 4.

I can send a patch but would like to know if the expected solution is to add back support for this, or to update the documentation to no longer indicate that this setting is read.

Checklist

  • I have included the output of celery -A proj report in the issue.
    (if you are not able to do this, then at least specify the Celery
    version affected).

Version 4.0.2 (latentcall)

  • I have verified that the issue exists against the master branch of Celery.

Steps to reproduce

Run Celery from a Django project that has the TIME_ZONE setting set, but which does not specify CELERY_TIMEZONE.

Expected behavior

The configured timezone (e.g. app.conf.timezone is the same as that in Django's TIME_ZONE setting).

Actual behavior

The configured timezone is None.

Activity

  1. RabidCicada commented on Jul 7, 2017

    @RabidCicada

    I also ran into and noticed this. I reference this behavior on celery/django-celery-beat#57. I would like it fixed soas to make it easier to keep them in sync from the config file.

  2. georgepsarakis commented on Jul 14, 2017

    @georgepsarakis
    Contributor

    @izquierdo @RabidCicada I believe you need to combine it with the USE_TZ=True setting. For reference see also here.

  3. RabidCicada commented on Jul 16, 2017

    @RabidCicada

    USE_TZ is set to True as well documented. This behavior persists.

  4. georgepsarakis commented on Jul 16, 2017

    @georgepsarakis
    Contributor

    I think you also need to set CELERY_ENABLE_UTC=False. Check the discussion in #3753 .

  5. added this to the milestone on Dec 19, 2017
  6. removed this from the milestone on Jan 17, 2018
  7. bhrutledge commented on Feb 16, 2018

    @bhrutledge

    @auvipy Can you elaborate on why this was closed? Was it fixed? Or is this now expected behavior (counter to the docs)?

  8. kylebebak commented on May 1, 2018

    @kylebebak

    @georgepsarakis @auvipy
    It's obvious this should not have been closed. This is a bug that runs counter to the documentation.

    I'm running celery==4.1.0 and Django==1.11.6.

    Regardless of what I set for CELERY_TIMEZONE and TIMEZONE, Celery beat uses UTC. No combination of True and False for CELERY_ENABLE_UTC and USE_TZ makes a difference.

  9. georgepsarakis commented on May 1, 2018

    @georgepsarakis
    Contributor

    @kylebebak thanks for reporting back. There have been some Celery Beat & timezone fixes in the latest release (4.2.0rc3), is it possible that you can try with that?

  10. kylebebak commented on May 2, 2018

    @kylebebak

    @georgepsarakis Thank you for the quick reply. I'll try with 4.2.0rc3 and let you know if that solves the problem, but I probably won't get around to it for a week or so.

    I'm in a time zone that's between 5 and 6 hours behind UTC depending on DST, so for the time being I just added 5.5 hours to to all of my crontab Celery beat tasks.

  11. thedrow commented on May 13, 2018

    @thedrow
    Contributor

    @kylebebak Have you tried it yet?

  12. Jamim commented on May 14, 2018

    @Jamim
    Contributor

    I'm pretty sure this issue is related to #2649.

  13. auvipy commented on Aug 12, 2018

    @auvipy
    Member

    is this fixed by #3867 ?

  14. sponrad commented on Jan 1, 2020

    @sponrad

    is this fixed by #3867 ?

    @auvipy It appears it isn't.

    I just stumbled in here after upgrading from 3.1.25 to 4.x. My periodic tasks are no longer honoring Django's timezone settings just as described by izquierdo.

    Django version: 1.11.3
    Celery version: tried on 4.0.0 and 4.4.0
    Relevant Django settings:

    USE_TZ = True
    TIME_ZONE = 'America/Los_Angeles'
    

    app.conf.timezone returns None and my periodic tasks fire on UTC time.

    Setting the celery timezone setting (namespaced as CELERY_TIMEZONE for my install) results in app.conf.timezone having a value.

    This is a bug in conflict with this documentation:

    Celery recommends and is compatible with the new USE_TZ setting introduced in Django 1.4.
    For Django users the time zone specified in the TIME_ZONE setting will be used, or you can specify a custom time zone for Celery alone by using the timezone setting.

  15. vanschelven commented on Jul 7, 2022

    @vanschelven
    Contributor

    AFAICS this problem still exists. Running celery v5.2.7, django 3.2.11.

    settings.py:

    TIME_ZONE = 'CET'
    
    CELERY_BEAT_SCHEDULE = {
        'debug_task': {
            'task': 'project.celery.debug_task',  # this is the thing from the tutorial
            'schedule': crontab(minute="14", hour="11")  # or whatever is right about to come up
        },
    }
    
    # CELERY_TIMEZONE = TIME_ZONE  # when this is turned on everything works as documented
    

    It appears that app.conf.timezone is simply None.

    Searching the code (case insensitive) for time_zone reveals only 1 location:

    return self.first('timezone', 'time_zone')

    It appears that's the part that's broken.

    Looking at the actual contents of the configuration object, I'd say that the latter time_zone should simply be upper-cased.

  16. reopened this on Jul 7, 2022
  17. added this to the 5.3 milestone on Jul 7, 2022
  18. added a commit that references this issue on Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions