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

Task.request is not celery.worker.request.Request (during task_prerun) #103

Closed
flaeppe opened this issue Feb 10, 2023 · 0 comments
Closed
Labels
bug Something isn't working

Comments

@flaeppe
Copy link

flaeppe commented Feb 10, 2023

Task.request is typed like below

@property
def request(self) -> Request: ...

With the following task_prerun receiver

@signals.task_prerun.connect
def task_prerun_receiver(*args: Any, **kwargs: Any) -> None:
    task: Task = kwargs["sender"]
    ...
    logger.info("task_prerun_receiver", task_request_dict=task.request.request_dict)

I'm getting at traceback like

Traceback (most recent call last):
  File "/app/venv/lib/python3.10/site-packages/celery/utils/dispatch/signal.py", line 276, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/app/src/myapp/celery/app.py", line 59, in task_prerun_receiver
    logger.info("task_prerun_receiver", task_request_dict=task.request.request_dict)
AttributeError: 'Context' object has no attribute 'request_dict'

Celery documents "Sender is the task object being executed"
Ref: https://docs.celeryq.dev/en/stable/userguide/signals.html#task-prerun

I thought task.request was a Request object, but at least in the case of a receiver on task_prerun it's rather an instance of celery.app.task.Context.

@sbdchd sbdchd added the bug Something isn't working label Feb 11, 2023
mrcljx added a commit to mrcljx/celery-types that referenced this issue Aug 2, 2023
@kodiakhq kodiakhq bot closed this as completed in 559d424 Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants