Skip to content

"Next Steps" error propagation example does not match the current behavior. #5964

Description

@adyouri

Checklist

  • 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 master branch.
  • I have included all related issues and possible duplicate issues in this issue
    (If there are none, check this box anyway).

Related Issues and Possible Duplicates

Related Issues

Possible Duplicates

  • None

Description

In Calling Tasks:

You can also inspect the exception and traceback if the task raised an exception, in fact result.get() will propagate any errors by default:

>>> res = add.delay(2)
>>> res.get(timeout=1)

This example is not working as described because add.delay(2) results in the following error before the user is able to call res.get(timeout=1):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/abd/python/celery/env/lib/python3.8/site-packages/celery/app/task.py", line 425, in delay
    return self.apply_async(args, kwargs)
  File "/home/abd/python/celery/env/lib/python3.8/site-packages/celery/app/task.py", line 530, in apply_async
    check_arguments(*(args or ()), **(kwargs or {}))
TypeError: add() missing 1 required positional argument: 'y'

I suppose check_arguments() is a new function?

Suggestions

Change the example from:

>>> res = add.delay(2)
>>> res.get(timeout=1)

To an integer and string addition:

>>> res = add.delay(2, '2')
>>> res.get(timeout=1)

This way res = add.delay(2, '2') won't raise TypeError: add() missing 1 required positional argument: 'y'. And res.get(timeout=1) will propagate the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/abd/python/celery/env/lib/python3.8/site-packages/celery/result.py", line 221, in get
    return self.backend.wait_for_pending(
  File "/home/abd/python/celery/env/lib/python3.8/site-packages/celery/backends/asynchronous.py", line 195, in wait_for_pending
    return result.maybe_throw(callback=callback, propagate=propagate)
  File "/home/abd/python/celery/env/lib/python3.8/site-packages/celery/result.py", line 333, in maybe_throw
    self.throw(value, self._to_remote_traceback(tb))
  File "/home/abd/python/celery/env/lib/python3.8/site-packages/celery/result.py", line 326, in throw
    self.on_ready.throw(*args, **kwargs)
  File "/home/abd/python/celery/env/lib/python3.8/site-packages/vine/promises.py", line 244, in throw
    reraise(type(exc), exc, tb)
  File "/home/abd/python/celery/env/lib/python3.8/site-packages/vine/five.py", line 195, in reraise
    raise value
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions