Skip to content

ETA field on task is not correctly parsed in celery>=5.3.0 and python<3.11 #8499

@jaapz

Description

@jaapz

Checklist

  • I have verified that the issue exists against the main branch of Celery.
  • This has already been asked to the discussions forum first.
  • I have read the relevant section in the
    contribution guide
    on reporting bugs.
  • I have checked the issues list
    for similar or identical bug reports.
  • I have checked the pull requests list
    for existing proposed fixes.
  • I have checked the commit log
    to find out if the bug was already fixed in the main branch.
  • I have included all related issues and possible duplicate issues
    in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

  • 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).
  • I have verified that the issue exists against the main branch of Celery.
  • I have included the contents of pip freeze in the issue.
  • I have included all the versions of all the external dependencies required
    to reproduce this bug.

Optional Debugging Information

  • I have tried reproducing the issue on more than one Python version
    and/or implementation.
  • I have tried reproducing the issue on more than one message broker and/or
    result backend.
  • I have tried reproducing the issue on more than one version of the message
    broker and/or result backend.
  • I have tried reproducing the issue on more than one operating system.
  • I have tried reproducing the issue on more than one workers pool.
  • I have tried reproducing the issue with autoscaling, retries,
    ETA/Countdown & rate limits disabled.
  • I have tried reproducing the issue after downgrading
    and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

  • None

Possible Duplicates

  • None

Environment & Settings

Celery version:

celery report Output:

Steps to Reproduce

Required Dependencies

  • Minimal Python Version: N/A or Unknown
  • Minimal Celery Version: 5.3.0
  • Minimal Kombu Version: N/A or Unknown
  • Minimal Broker Version: N/A or Unknown
  • Minimal Result Backend Version: N/A or Unknown
  • Minimal OS and/or Kernel Version: N/A or Unknown
  • Minimal Broker Client Version: N/A or Unknown
  • Minimal Result Backend Client Version: N/A or Unknown

Python Packages

pip freeze Output:

Other Dependencies

Details

N/A

Minimally Reproducible Test Case

Details

Expected Behavior

When adding a task to the queue with a valid iso8601 ETA field set (for example) '2023-09-12T15:39:16Z, celery should accept the task and execute it correspondingly.

Actual Behavior

compose-worker_fast-5  | [2023-09-12 15:39:16,095: ERROR/MainProcess] Received invalid task message: invalid ETA value '
2023-09-12T15:39:16Z': Invalid isoformat string: '2023-09-12T15:39:16Z'
compose-worker_fast-5  | The message has been ignored and discarded.
compose-worker_fast-5  |
compose-worker_fast-5  | Please ensure your message conforms to the task
compose-worker_fast-5  | message protocol as described here:
compose-worker_fast-5  | https://docs.celeryq.dev/en/latest/internals/protocol.html
compose-worker_fast-5  |
compose-worker_fast-5  | The full contents of the message body was:
compose-worker_fast-5  | {'id': '', 'task': 'tasks.notification.alert.send_notification_alert_mail', 'args': [3022248],
'kwargs': {}, 'retries': 0, 'eta': '2023-09-12T15:39:16Z'} (142b)
compose-worker_fast-5  | Traceback (most recent call last):
compose-worker_fast-5  |   File "/home/celery/venv/lib/python3.10/site-packages/celery/worker/request.py", line 135, in
__init__
compose-worker_fast-5  |     eta = maybe_iso8601(eta)
compose-worker_fast-5  |   File "/home/celery/venv/lib/python3.10/site-packages/celery/utils/time.py", line 291, in mayb
e_iso8601
compose-worker_fast-5  |     return datetime.fromisoformat(dt)
compose-worker_fast-5  | ValueError: Invalid isoformat string: '2023-09-12T15:39:16Z'
compose-worker_fast-5  |
compose-worker_fast-5  | During handling of the above exception, another exception occurred:
compose-worker_fast-5  |
compose-worker_fast-5  | Traceback (most recent call last):
compose-worker_fast-5  |   File "/home/celery/venv/lib/python3.10/site-packages/celery/worker/consumer/consumer.py", lin
e 668, in on_task_received
compose-worker_fast-5  |     strategy(
compose-worker_fast-5  |   File "/home/celery/venv/lib/python3.10/site-packages/celery/worker/strategy.py", line 146, in
 task_message_handler
compose-worker_fast-5  |     req = Req(
compose-worker_fast-5  |   File "/home/celery/venv/lib/python3.10/site-packages/celery/worker/request.py", line 137, in
__init__
compose-worker_fast-5  |     raise InvalidTaskError(
compose-worker_fast-5  | celery.exceptions.InvalidTaskError: invalid ETA value '2023-09-12T15:39:16Z': Invalid isoformat
 string: '2023-09-12T15:39:16Z'

The problem is that in 5.3.0 this change switched to python's native datetime.datetime.isoformat to parse iso8601 dates in eta field. However, python<3.11 implemented this incorrectly (which is probably why you implemented your own parser function in the first place). When running celery 5.3.0 in python 3.11, this will work, but when running in 3.10 or lower the above ValueError will be thrown.

The fix is probably as simple as checking your python version and using your own (deprecated) function in python 3.10 or lower and using python's native datetime method in python 3.11 or higher

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions