Skip to content

query_task does not return task #5321

Closed

Description

@NadavK

Checklist

  • I have included the output of celery -A proj report in the issue.
  • I have included the contents of pip freeze in the issue.
  • I have verified that the issue exists against the master branch of Celery.
  • 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 workers pool.
  • I have tried reproducing the issue with retries, ETA/Countdown & rate limits disabled.

Environment & Settings

Celery version: 4.2.1 (windowlicker)
Report:

Details ``` $ celery -A djhome report DEBUG [2019-02-04 17:55:09,071] asyncio: Using selector: EpollSelector DEBUG [2019-02-04 17:55:10,564] amqp: Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@djhome-dev', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'platform': 'Erlang/OTP', 'product': 'RabbitMQ', 'version': '3.6.6'}, mechanisms: [b'AMQPLAIN', b'PLAIN'], locales: ['en_US'] DEBUG [2019-02-04 17:55:10,570] amqp: using channel_id: 1 DEBUG [2019-02-04 17:55:10,579] amqp: Channel open DEBUG [2019-02-04 17:55:10,679] amqp: Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@djhome-dev', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'platform': 'Erlang/OTP', 'product': 'RabbitMQ', 'version': '3.6.6'}, mechanisms: [b'AMQPLAIN', b'PLAIN'], locales: ['en_US'] DEBUG [2019-02-04 17:55:10,684] amqp: using channel_id: 1 DEBUG [2019-02-04 17:55:10,689] amqp: Channel open

software -> celery:4.2.1 (windowlicker) kombu:4.2.2-post1 py:3.6.8
billiard:3.5.0.3 py-amqp:2.2.2
platform -> system:Linux arch:32bit, ELF imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:amqp results:disabled

ABSOLUTE_URL_OVERRIDES: {
}
CACHES: {
'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
CACHE_MIDDLEWARE_ALIAS: 'default'
CACHE_MIDDLEWARE_KEY_PREFIX: ''
CACHE_MIDDLEWARE_SECONDS: 600
CELERYD_LOG_LEVEL: 'INFO'
CELERYD_TIMER_PRECISION: 0.5
CELERY_ACCEPT_CONTENT: ['json']
CELERY_BROKER_URL: 'amqp://guest:
@localhost:5672//'
CELERY_IGNORE_RESULT: True
CELERY_TASK_IGNORE_RESULT: True
CELERY_TASK_SERIALIZER: 'json'
CELERY_TIMEZONE: 'Asia/Jerusalem'
CHANNEL_LAYERS: {
'default': { 'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {'hosts': [('127.0.0.1', 6379)]}},
'default_old': { 'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {'capacity': 1000, 'prefix': 'mysite'}}}
DEBUG: True
DEBUG_PROPAGATE_EXCEPTIONS: False
DECIMAL_SEPARATOR: '.'
FILE_CHARSET: 'utf-8'
FILE_UPLOAD_DIRECTORY_PERMISSIONS: None
FILE_UPLOAD_HANDLERS: ['django.core.files.uploadhandler.MemoryFileUploadHandler',
'django.core.files.uploadhandler.TemporaryFileUploadHandler']
FILE_UPLOAD_MAX_MEMORY_SIZE: 2621440
FILE_UPLOAD_PERMISSIONS: None
FILE_UPLOAD_TEMP_DIR: None
FIRST_DAY_OF_WEEK: 0
FIXTURE_DIRS:
('fixtures/',)
FORCE_SCRIPT_NAME: None
FORMAT_MODULE_PATH: None
FORM_RENDERER: 'django.forms.renderers.DjangoTemplates'
GENERATE_REQUEST_ID_IF_NOT_IN_HEADER: True
IGNORABLE_404_URLS: []
INSTALLED_APPS: ['channels',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'taggit',
'guardian',
'rest_framework',
'rest_framework.authtoken']
INTERNAL_IPS: []
JWT_AUTH: {
'JWT_ALLOW_REFRESH': True,
'JWT_EXPIRATION_DELTA': datetime.timedelta(14),
'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(36500),
'JWT_VERIFY_EXPIRATION': False}
MESSAGE_STORAGE: 'django.contrib.messages.storage.fallback.FallbackStorage'
MIDDLEWARE: None
MIDDLEWARE_CLASSES: ['log_request_id.middleware.RequestIDMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.common.BrokenLinkEmailsMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']

</details>

# Steps to Reproduce

## Required Dependencies
<!-- Please fill the required dependencies to reproduce this issue -->
* **Minimal Python 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

### Python Packages
<!-- Please fill the contents of pip freeze below -->
<details>
aioredis==1.2.0
amqp==2.2.2
appdirs==1.4.3
argh==0.26.2
arrow==0.10.0
asgiref==2.3.2
astral==1.7.1
async-timeout==3.0.1
attrs==18.2.0
autobahn==17.10.1
Automat==0.6.0
Babel==2.5.1
backports-abc==0.5
backports.ssl-match-hostname==3.5.0.1
billiard==3.5.0.3
blessed==1.14.2
celery==4.2.1
certifi==2017.11.5
channels==2.1.6
channels-redis==2.3.3
chardet==3.0.4
chaussette==1.3.0
cheroot==5.10.0
CherryPy==12.0.1
circus==0.15.0
constantly==15.1.0
daphne==2.2.4
Django==1.11.7
django-cors-headers==2.4.0
django-filter==1.1.0
django-guardian==1.4.9
django-log-request-id==1.3.2
django-picklefield==1.0.0
django-taggit==0.22.1
django-taggit-serializer==0.1.5
djangorestframework==3.9.1
djangorestframework-jwt==1.11.0
flower==0.9.2
future==0.16.0
greenlet==0.4.12
gunicorn==19.7.1
hiredis==0.3.1
hyperlink==17.3.1
idna==2.6
incremental==17.5.0
jaraco.classes==1.4.3
kombu==4.2.2.post1
Markdown==2.6.9
meld3==1.0.2
msgpack==0.6.0
msgpack-python==0.4.8
packaging==16.8
parsedatetime==2.4
pathtools==0.1.2
Phidget22==1.0.0
portend==2.2
psutil==5.4.8
pydevd==1.1.1
PyHamcrest==1.9.0
PyJWT==1.7.1
pyluach==0.3.0.dev1
pyparsing==2.2.0
python-dateutil==2.6.1
pytz==2018.7
PyYAML==3.12
pyzmq==16.0.4
redis==2.10.6
requests==2.18.4
requests-futures==0.9.7
singledispatch==3.4.0.3
six==1.11.0
SQLAlchemy==1.1.15
tempora==1.9
tornado==4.5.2
Twisted==18.9.0
txaio==18.8.1
urllib3==1.22
vine==1.1.4
wcwidth==0.1.7
zope.interface==4.6.0
</details>

### Other Dependencies
<!--
Please provide system dependencies, configuration files
and other dependency information if applicable
-->
<details>
N/A
</details>

## Minimally Reproducible Test Case
<!--
Please provide a reproducible test case.
Refer to the Reporting Bugs section in our contribution guide.

We prefer submitting test cases in the form of a PR to our integration test suite.
If you can provide one, please mention the PR number below.
If not, please attach the most minimal code example required to reproduce the issue below.
If there test case is too large, please include a link to a gist or a repository below.
-->

<details>
```python

$ celery -A proj inspect scheduled
DEBUG [2019-02-04 20:24:58,358] [none] asyncio: Using selector: EpollSelector
DEBUG [2019-02-04 20:24:59,891] [none] amqp: Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@proj', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'platform': 'Erlang/OTP', 'product': 'RabbitMQ', 'version': '3.6.6'}, mechanisms: [b'AMQPLAIN', b'PLAIN'], locales: ['en_US']
DEBUG [2019-02-04 20:24:59,898] [none] amqp: using channel_id: 1
DEBUG [2019-02-04 20:24:59,908] [none] amqp: Channel open
DEBUG [2019-02-04 20:25:00,027] [none] amqp: Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@proj', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'platform': 'Erlang/OTP', 'product': 'RabbitMQ', 'version': '3.6.6'}, mechanisms: [b'AMQPLAIN', b'PLAIN'], locales: ['en_US']
DEBUG [2019-02-04 20:25:00,033] [none] amqp: using channel_id: 1
DEBUG [2019-02-04 20:25:00,038] [none] amqp: Channel open
-> celery@proj: OK
* {'eta': '2019-02-04T21:00:00+02:00', 'priority': 6, 'request': {'id': '5b3fc76e-df3a-4d5c-b46c-66557f00879f', 'name': 'proj.celery.set_from_schedule', 'args': "(22)", 'kwargs': '{}', 'type': 'proj.celery.set_output_state_from_schedule', 'hostname': 'celery@proj', 'time_start': None, 'acknowledged': False, 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': False}, 'worker_pid': None}}

$ celery -A proj inspect query_task
DEBUG [2019-02-04 20:27:39,477] [none] asyncio: Using selector: EpollSelector
DEBUG [2019-02-04 20:27:41,056] [none] amqp: Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@proj', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'platform': 'Erlang/OTP', 'product': 'RabbitMQ', 'version': '3.6.6'}, mechanisms: [b'AMQPLAIN', b'PLAIN'], locales: ['en_US']
DEBUG [2019-02-04 20:27:41,063] [none] amqp: using channel_id: 1
DEBUG [2019-02-04 20:27:41,074] [none] amqp: Channel open
DEBUG [2019-02-04 20:27:41,176] [none] amqp: Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@proj', 'copyright': 'Copyright (C) 2007-2016 Pivotal Software, Inc.', 'information': 'Licensed under the MPL. See http://www.rabbitmq.com/', 'platform': 'Erlang/OTP', 'product': 'RabbitMQ', 'version': '3.6.6'}, mechanisms: [b'AMQPLAIN', b'PLAIN'], locales: ['en_US']
DEBUG [2019-02-04 20:27:41,182] [none] amqp: using channel_id: 1
DEBUG [2019-02-04 20:27:41,188] [none] amqp: Channel open
-> celery@proj: OK
{}

Expected Behavior

Calling "inspect scheduled" correctly returns tasks.
I expect that "inspect query_task" on a specific task_id will return that task, but it returns {}

Actual Behavior

"inspect query_task" on a specific task_id returns {}

Activity

  1. auvipy commented on Apr 30, 2019

    @auvipy
    Member

    whats its update with celery 4.3?

  2. auvipy commented on May 6, 2019

    @auvipy
    Member

    will reopen after feedback

  3. gomeslucasm commented on Feb 18, 2022

    @gomeslucasm

    any updated? I'm experiencing the same problem, the task appears using .scheduled() but doesn't appear when I use .query_task(id)

  4. reopened this on Feb 19, 2022
  5. auvipy commented on Feb 19, 2022

    @auvipy
    Member

    can you provide more detail please

  6. added this to the 5.3.x milestone on Jul 4, 2022
  7. self-assigned this
    on Jul 4, 2022
  8. modified the milestones: 5.3.x, 5.5 on Jun 25, 2024
  9. modified the milestones: 5.5.0, 5.7.0 on Jun 10, 2025
  10. ghirailghiro commented on Aug 29, 2026

    @ghirailghiro
    Contributor

    Hi @auvipy reproduced this on main. The issue is that query_task looks up celery.worker.state.requests, but a task with an eta/countdown doesn't get added there until the ETA actually fires — before that it only exists in the consumer's timer, which is what scheduled reads from. So scheduled() sees it right away, query_task(id) returns nothing until it's about to run.

    Opened a fix here: #10535

    Here the code to reproduce the error:

    import threading
    import time
    
    from celery import Celery
    
    app = Celery('verify_issue_5321', broker='memory://', backend='cache+memory://')
    app.conf.worker_hijack_root_logger = False
    
    
    @app.task(name='demo.add')
    def add(x, y):
        return x + y
    
    
    def start_worker():
        worker = app.Worker(pool='solo', loglevel='WARNING', concurrency=1)
        thread = threading.Thread(target=worker.start, daemon=True)
        thread.start()
        return worker, thread
    
    
    def wait_for_worker(inspect, timeout=10):
        deadline = time.monotonic() + timeout
        while time.monotonic() < deadline:
            if inspect.ping():
                return True
            time.sleep(0.2)
        return False
    
    
    def main():
        worker, thread = start_worker()
        inspect = app.control.inspect()
    
        print('Waiting for worker to come up...')
        if not wait_for_worker(inspect):
            raise SystemExit('worker did not start in time')
    
        result = add.apply_async((2, 2), countdown=30)
        task_id = result.id
        print(f'Scheduled demo.add(2, 2) with countdown=30, task id: {task_id}')
        time.sleep(1)  # give the worker a moment to receive and schedule it
    
        print('inspect().scheduled() ->')
        scheduled = inspect.scheduled()
        print(scheduled)
    
        print(f'inspect().query_task({task_id!r}) ->')
        queried = inspect.query_task(task_id)
        print(queried)
    
        found_in_scheduled = any(
            entry.get('request', {}).get('id') == task_id
            for tasks in (scheduled or {}).values()
            for entry in tasks
        )
        found_in_query = any(
            task_id in tasks for tasks in (queried or {}).values()
        )
    
        print(f'Found via scheduled():  {found_in_scheduled}')
        print(f'Found via query_task(): {found_in_query}')
    
        worker.stop()
    
        if found_in_scheduled and not found_in_query:
            raise SystemExit('BUG REPRODUCED: task visible via scheduled() but not query_task()')
    
        assert found_in_scheduled, 'expected the task to be visible via scheduled()'
        assert found_in_query, 'expected the task to be visible via query_task()'
    
    if __name__ == '__main__':
        main()
    
    
  11. auvipy commented on Aug 31, 2026

    @auvipy
    Member

    cool! thanks lets continue in the pr

  12. auvipy commented on Sep 1, 2026

    @auvipy
    Member

    Here the code to reproduce the error:

    may be part of this reproducer can be used as integration test

  13. removed their assignment
    on Sep 7, 2026
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