Skip to content

Error in worker logs: KeyError: 'task_name' #49966

Closed as not planned
Closed as not planned

Description

@nicolamarangoni

Apache Airflow version

3.0.0

If "Other Airflow 2 version" selected, which one?

No response

What happened?

I'm testing a fresh 3.0.0 installation and started the worker with the command airflow celery worker, after the usual logs, I see the wollowing lines in the logs of the worker service:

[tasks]
. execute_workload
--- Logging error ---
Traceback (most recent call last):
File "/usr/local/lib/python3.12/logging/__init__.py", line 464, in format
return self._format(record)
File "/usr/local/lib/python3.12/logging/__init__.py", line 460, in _format
return self._fmt % values
KeyError: 'task_name'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/logging/__init__.py", line 1160, in emit
msg = self.format(record)
....

The service looks healthy however, but the installation has no DAGs at the moment therefore I didn't testet some DAG executions yet.

What you think should happen instead?

The KeyError: 'task_name' should not happen.

How to reproduce

Install a fresh 3.0.0 from the greenfield and launch the worker with the command:
airflow celery worker

Operating System

Official docker image,

Versions of Apache Airflow Providers

No response

Deployment

Other

Deployment details

Official docker image running on AWS ECS.

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Apr 29, 2025
  2. amoghrajesh commented on May 8, 2025

    @amoghrajesh
    Contributor

    @nicolamarangoni can you help with your installation steps?

  3. aaron-y-chen commented on Jun 24, 2025

    @aaron-y-chen
    Contributor

    I can't reproduce it either, could you share your celery version?

  4. nicolamarangoni commented on Jul 21, 2025

    @nicolamarangoni
    ContributorAuthor

    My installation steps consist in a huge terraform deployment.
    However, I think that the error happen here:
    celery/apps/worker.py, line 176: https://github.com/celery/celery/blob/main/celery/apps/worker.py
    This is the code:

        def on_consumer_ready(self, consumer):
            signals.worker_ready.send(sender=consumer)
            logger.info('%s ready.', safe_str(self.hostname))
    

    It's related to this issue: #42136 (comment)

  5. nicolamarangoni commented on Jul 21, 2025

    @nicolamarangoni
    ContributorAuthor

    After setting AIRFLOW__CORE__EXECUTION_API_SERVER_URL I still have the same erro but in another position:
    https://github.com/celery/celery/blob/main/celery/worker/consumer/connection.py line 22:

        def start(self, c):
            c.connection = c.connect()
            info('Connected to %s', c.connection.as_uri())
    
  6. nicolamarangoni commented on Jul 21, 2025

    @nicolamarangoni
    ContributorAuthor
  7. amoghrajesh commented on Jul 22, 2025

    @amoghrajesh
    Contributor

    @nicolamarangoni I merged a recent fix related to this: Handle invalid execution API urls in supervisor #53082

    Could you pull in that commit in your deployment and try again?

  8. nicolamarangoni commented on Jul 24, 2025

    @nicolamarangoni
    ContributorAuthor

    @amoghrajesh Thank you for the hint. I downloaded and substituted the supervisor.py file into my image and restarted the ECS services. I still see the error (see logs in attachment). However I think it's only a false positive because the ECS service of the worker is running.
    Currently my issue is this one: #42136 (comment)
    I don't know if the 2 issues are related.

  9. amoghrajesh commented on Jul 28, 2025

    @amoghrajesh
    Contributor

    @nicolamarangoni could you check what's set as config for base_url?

  10. nicolamarangoni commented on Jul 28, 2025

    @nicolamarangoni
    ContributorAuthor

    @amoghrajesh I have this in my config:

    airflow config list
    ....
    base_url = https://dev.myinternal.company.domain.tech
    ....
    

    It's the URL of the web UI

  11. amoghrajesh commented on Jul 29, 2025

    @amoghrajesh
    Contributor

    @nicolamarangoni looking more carefully, this could be a logging error

    Your logging formatter is trying to substitute a field %(task_name)s, but the log record being emitted doesn’t always have that attribute.

    Check your task code for potential usage of task_name or if you could share your dag code

  12. nicolamarangoni commented on Jul 29, 2025

    @nicolamarangoni
    ContributorAuthor

    @amoghrajesh I did a fresh install of Airflow. There are currently no DAGs at all in the instance.
    I still see the same error at startup in the worker logs.
    This error is not related to any DAG/task run. It appears at startup.

  13. 4 remaining items

  14. nicolamarangoni commented on Aug 5, 2025

    @nicolamarangoni
    ContributorAuthor

    @amoghrajesh I'm able to run tasks now.
    However, the error in the worker logs at startup is still there.
    Wouldn't be better to wait for versionb 3.0.4 ?

  15. nicolamarangoni commented on Aug 5, 2025

    @nicolamarangoni
    ContributorAuthor

    log-events-viewer-result.csv

    I see an additional error in the worker logs when I execute a task, even if the task is successful (see attached logs).

  16. removed
    needs-triage
    on Oct 31, 2025
  17. nicolamarangoni commented on Dec 15, 2025

    @nicolamarangoni
    ContributorAuthor

    Hello,

    in version 3.1.5, this behavior is still present at startup in the worker logs (see attachment).

    Regards,
    Nicola

    worker-logs-315.csv

  18. potiuk commented on Dec 16, 2025

    @potiuk
    Member

    I think there is something terrribly wrong in your logging configuration. I recommend you to remove custom configuration you have and gradually add your modifications and customisations you have done - there is no way for us to know - or debug - your setup of logging, you likely inherited that from someone in the past and now it's unfortunately your task to debug it - and if needed to find-out - bisecting it by intelligent guessing which part of the configuration is causing it - look at your local_settings and any special customisations you have on top of standard airflow configuration.

    My best guess is that somewhere some of your logging attempts to add (in a custom way) and expects "task_name" to be added when logged, but what it is and how I think only inspecting your customisations might tell.

  19. kiros19 commented on Feb 4, 2026

    @kiros19

    I've got the same error on setup:
    Airlfow 3.1.6 + apache-airflow-providers-fab 3.1.2 (trying to solve apiserver UI not opening after some time)
    CeleryExecutor + rabbitMQ:3.13.7 Erlang 26.2.5.13
    Docker

    I've seen the error before, but i believe some reloads, version changes made it dissapear someway
    The problem as i see it:
    Celery has some buit-in log formatting setting, that's failing
    That's causing worker to close AMQP connection to rabbit

    I believe that logging config is built-in as my config is default and has 'taskname' everywhere, not task_name
    And logs were not modified from scripts or anything, it's clean

    The №1 sus thing is that airflow jobs still executed ok. Nothing is failing.
    But how could it be ok, if AMQP is closed instanly on opening, due to that celery logging error?

    Other sus thing - Error is not appearing for my prod setup:
    Airlfow 3.1.5 + airflow-providers-fab 3.0.3
    And I'm not sure I've seen it for my prev test setup (not 100% sure here):
    Airlfow 3.1.6 + apache-airflow-providers-fab 3.1.1

    Below are my rabbit,celery logs and my logging config

    RABBITMQ:
    --ok
    2026-02-04 06:46:26.518060+00:00 [info] <0.3105.0> accepting AMQP connection <0.3105.0> (100.18.0.4:46058 -> 100.18.0.2:5672)
    2026-02-04 06:46:26.520354+00:00 [info] <0.3105.0> connection <0.3105.0> (100.1.0.4:46058 -> 100.18.0.2:5672): user 'airflow' authenticated and granted access to vhost 'airflow_queue'
    2026-02-04 06:46:26.528031+00:00 [info] <0.3122.0> accepting AMQP connection <0.3122.0> (100.18.0.4:46064 -> 100.18.0.2:5672)
    2026-02-04 06:46:26.529746+00:00 [info] <0.3122.0> connection <0.3122.0> (100.0.4:46064 -> 100.18.0.2:5672): user 'airflow' authenticated and granted access to vhost 'airflow_queue'
    --instanlty closing
    2026-02-04 06:46:26.922223+00:00 [warning] <0.3105.0> closing AMQP connection <0.3105.0> (100.18.0.4:46058 -> 100.18.0.2:5672, vhost: 'airflow_queue', user: 'airflow'):
    2026-02-04 06:46:26.922223+00:00 [warning] <0.3105.0> client unexpectedly closed TCP connection
    2026-02-04 06:46:26.922550+00:00 [warning] <0.3122.0> closing AMQP connection <0.3122.0> (100.18.0.4:46064 -> 100.18.0.2:5672, vhost: 'airflow_queue', user: 'airflow'):
    2026-02-04 06:46:26.922550+00:00 [warning] <0.3122.0> client unexpectedly closed TCP connection

    WORKER:
    --- Logging error ---
    Traceback (most recent call last):
    File "/usr/python/lib/python3.12/logging/init.py", line 464, in format
    return self._format(record)
    ^^^^^^^^^^^^^^^^^^^^
    File "/usr/python/lib/python3.12/logging/init.py", line 460, in _format
    return self._fmt % values
    ~~~~~~~~~~^~~~~~~~
    KeyError: 'task_name'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/usr/python/lib/python3.12/logging/init.py", line 1160, in emit
    msg = self.format(record)
    ^^^^^^^^^^^^^^^^^^^
    File "/usr/python/lib/python3.12/logging/init.py", line 999, in format
    return fmt.format(record)
    ^^^^^^^^^^^^^^^^^^
    File "/usr/python/lib/python3.12/logging/init.py", line 706, in format
    s = self.formatMessage(record)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/python/lib/python3.12/logging/init.py", line 675, in formatMessage
    return self._style.format(record)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/python/lib/python3.12/logging/init.py", line 466, in format
    raise ValueError('Formatting field not found in record: %s' % e)
    ValueError: Formatting field not found in record: 'task_name'
    Call stack:
    File "/home/airflow/.local/bin/airflow", line 7, in
    sys.exit(main())
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/main.py", line 55, in main
    args.func(args)
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/cli_config.py", line 49, in command
    return func(*args, **kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/cli.py", line 114, in wrapper
    return f(*args, **kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/celery/cli/celery_command.py", line 66, in wrapper
    providers_configuration_loaded(func)(*args, **kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/providers_configuration_loader.py", line 54, in wrapped_function
    return func(*args, **kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/celery/cli/celery_command.py", line 293, in worker
    _run_command_with_daemon_option(
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/celery/cli/celery_command.py", line 52, in _run_command_with_daemon_option
    run_command_with_daemon_option(*args, **kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/commands/daemon_utils.py", line 86, in run_command_with_daemon_option
    callback()
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/celery/cli/celery_command.py", line 286, in run_celery_worker
    celery_app.worker_main(options)
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/app/base.py", line 487, in worker_main
    self.start(argv=argv)
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/app/base.py", line 467, in start
    celery.main(args=argv, standalone_mode=False)
    File "/home/airflow/.local/lib/python3.12/site-packages/click/core.py", line 1406, in main
    rv = self.invoke(ctx)
    File "/home/airflow/.local/lib/python3.12/site-packages/click/core.py", line 1873, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/home/airflow/.local/lib/python3.12/site-packages/click/core.py", line 1269, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "/home/airflow/.local/lib/python3.12/site-packages/click/core.py", line 824, in invoke
    return callback(*args, **kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/click/decorators.py", line 34, in new_func
    return f(get_current_context(), *args, **kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/bin/base.py", line 135, in caller
    return f(ctx, *args, **kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/bin/worker.py", line 367, in worker
    worker.start()
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/worker/worker.py", line 203, in start
    self.blueprint.start(self)
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/bootsteps.py", line 116, in start
    step.start(parent)
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/bootsteps.py", line 365, in start
    return self.obj.start()
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/worker/consumer/consumer.py", line 346, in start
    blueprint.start(self)
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/bootsteps.py", line 116, in start
    step.start(parent)
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/worker/consumer/consumer.py", line 788, in start
    c.loop(*c.loop_args())
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/worker/loops.py", line 96, in asynloop
    next(loop)
    File "/home/airflow/.local/lib/python3.12/site-packages/kombu/asynchronous/hub.py", line 310, in create_loop
    item()
    File "/home/airflow/.local/lib/python3.12/site-packages/vine/promises.py", line 158, in call
    retval = fun(*final_args, **final_kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/kombu/transport/base.py", line 230, in _read
    drain_events(timeout=0)
    File "/home/airflow/.local/lib/python3.12/site-packages/amqp/connection.py", line 526, in drain_events
    while not self.blocking_read(timeout):
    File "/home/airflow/.local/lib/python3.12/site-packages/amqp/connection.py", line 532, in blocking_read
    return self.on_inbound_frame(frame)
    File "/home/airflow/.local/lib/python3.12/site-packages/amqp/method_framing.py", line 77, in on_frame
    callback(channel, msg.frame_method, msg.frame_args, msg)
    File "/home/airflow/.local/lib/python3.12/site-packages/amqp/connection.py", line 538, in on_inbound_method
    return self.channels[channel_id].dispatch_method(

    File "/home/airflow/.local/lib/python3.12/site-packages/amqp/abstract_channel.py", line 156, in dispatch_method
    listener(*args)
    File "/home/airflow/.local/lib/python3.12/site-packages/amqp/channel.py", line 1629, in _on_basic_deliver
    fun(msg)
    File "/home/airflow/.local/lib/python3.12/site-packages/kombu/messaging.py", line 668, in _receive_callback
    return on_m(message) if on_m else self.receive(decoded, message)
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/worker/consumer/consumer.py", line 694, in on_task_received
    strategy(
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/worker/strategy.py", line 207, in task_message_handler
    [callback(req) for callback in callbacks]
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/worker/autoscale.py", line 96, in maybe_scale
    self.pool.maintain_pool()
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/pool.py", line 1351, in maintain_pool
    self._maintain_pool()
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/pool.py", line 1343, in _maintain_pool
    self._repopulate_pool(joined)
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/pool.py", line 1328, in _repopulate_pool
    self._create_worker_process(self._avail_index())
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/concurrency/asynpool.py", line 493, in _create_worker_process
    return super()._create_worker_process(i)
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/pool.py", line 1158, in _create_worker_process
    w.start()
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/process.py", line 120, in start
    self._popen = self._Popen(self)
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/context.py", line 331, in _Popen
    return Popen(process_obj)
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/popen_fork.py", line 22, in init
    self._launch(process_obj)
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/popen_fork.py", line 77, in _launch
    code = process_obj._bootstrap()
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/process.py", line 323, in _bootstrap
    self.run()
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/process.py", line 110, in run
    self._target(*self._args, **self._kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/pool.py", line 292, in call
    sys.exit(self.workloop(pid=pid))
    File "/home/airflow/.local/lib/python3.12/site-packages/billiard/pool.py", line 362, in workloop
    result = (True, prepare_result(fun(*args, **kwargs)))
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/app/trace.py", line 694, in fast_trace_task
    R, I, T, Rstr = tasks[task].trace(
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/app/trace.py", line 479, in trace_task
    R = retval = fun(*args, **kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/celery/app/trace.py", line 779, in protected_call
    return self.run(*args, **kwargs)
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/celery/executors/celery_executor_utils.py", line 154, in execute_workload
    log.info("[%s] Executing workload in Celery: %s", celery_task_id, workload)
    Message: '[%s] Executing workload in Celery: %s'

    CONFIG:
    [logging]
    base_log_folder = /opt/airflow/logs
    remote_logging = False
    remote_log_conn_id =
    delete_local_logs = False
    google_key_path =
    remote_base_log_folder =
    remote_task_handler_kwargs =
    encrypt_s3_logs = False
    logging_level = INFO
    celery_logging_level = WARNING
    fab_logging_level = WARNING
    logging_config_class =
    colored_console_log = True
    #log_format = [%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s
    log_format = [%%(asctime)s] {%%(filename)s:%%(lineno)d} %%(levelname)s - %%(message)s
    #log_format = %(asctime)s [%(levelname)s] %(message)s
    callsite_parameters = filename,lineno
    #simple_log_format = %(asctime)s %(levelname)s - %(message)s
    simple_log_format = %%(asctime)s %%(levelname)s - %%(message)s
    dag_processor_log_target = file
    dag_processor_log_format = [%%(asctime)s] [SOURCE:DAG_PROCESSOR] {%%(filename)s:%%(lineno)d} %%(levelname)s - %%(message)s
    dag_processor_child_process_log_directory = /opt/airflow/logs/dag_processor
    log_formatter_class = airflow.utils.log.timezone_aware.TimezoneAware
    secret_mask_adapter =
    min_length_masked_secret = 5
    task_log_prefix_template =
    log_filename_template = dag_id={{ ti.dag_id }}/run_id={{ ti.run_id }}/task_id={{ ti.task_id }}/{%% if ti.map_index >= 0 %%}map_index={{ ti.map_index }}/{%% endif %%}attempt={{ try_number|default(ti.try_number) }}.log
    task_log_reader = task
    extra_logger_names =
    worker_log_server_port = 8793
    trigger_log_server_port = 8794
    #interleave_timestamp_parser =
    file_task_handler_new_folder_permissions = 0o775
    file_task_handler_new_file_permissions = 0o664
    celery_stdout_stderr_separation = False
    color_log_error_keywords = error,exception
    color_log_warning_keywords = warn
    [celery_kubernetes_executor]
    kubernetes_queue = kubernetes
    [celery]
    celery_app_name = airflow.providers.celery.executors.celery_executor
    worker_concurrency = 16
    #worker_autoscale =
    worker_prefetch_multiplier = 1
    worker_enable_remote_control = true
    broker_url = pyamqp://af:pwd@rabbitmq/af
    result_backend = db+postgresql://af:[email protected]:15432/af
    result_backend_sqlalchemy_engine_options =
    flower_host = 0.0.0.0
    flower_url_prefix =
    flower_port = 5555
    flower_basic_auth =
    sync_parallelism = 0
    celery_config_options = airflow.providers.celery.executors.default_celery.DEFAULT_CELERY_CONFIG
    ssl_active = False
    ssl_key =
    ssl_cert =
    ssl_cacert =
    pool = prefork
    operation_timeout = 1.0
    task_acks_late = True
    task_track_started = True
    task_publish_max_retries = 3
    extra_celery_config = {}
    #extra_celery_config = {"global_qos": false} -- False must be
    #broker_transport_options = {"global_qos": false}
    #worker_umask =
    [celery_broker_transport_options]
    #visibility_timeout =
    #sentinel_kwargs =

    And here is everything i've got on logging in docker compose (no celery logging format related stuff)
    AIRFLOW__LOGGING__BASE_LOG_FOLDER: '/opt/airflow/logs'
    AIRFLOW__LOGGING__DAG_PROCESSOR_CHILD_PROCESS_LOG_DIRECTORY: '/opt/airflow/logs/dag_processor_logs'
    AIRFLOW__LOGGING__REMOTE_LOGGING: 'true'
    AIRFLOW__LOGGING__REMOTE_BASE_LOG_FOLDER: 's3://dev/logs'
    AIRFLOW__LOGGING__REMOTE_LOG_CONN_ID: 'minio_s3_conn'
    AIRFLOW__LOGGING__DELETE_LOCAL_LOGS: 'true'

  20. kiros19 commented on Feb 5, 2026

    @kiros19

    same error with
    airflow 3.1.7
    fab 3.2.0
    apache-airflow-providers-celery==3.15.2
    celery==5.6.2

  21. aaron-y-chen commented on Feb 10, 2026

    @aaron-y-chen
    Contributor

    Hi, I found a bug in the celery worker log when setting celery_stdout_stderr_separation=True, and I opened a PR to fix it.

    However, I can't reproduce @kiros19's issue since their celery_stdout_stderr_separation is set to False. Could you tell me more about what happens when this error occurs? Does it cause your task to fail?

  22. kiros19 commented on Feb 10, 2026

    @kiros19

    Hello, @nailo2c
    No, the error doesn't cause task to fail. Worker is spamming with logs above; rabbitmq's saying, worker closes connection shortly after opening it

    UPD
    I've tested the solution @nailo2c offered.
    The solution is working, celery logging error dissapeared from worker logs
    RabbitMQ's still saying, worker is closing the connection.

    I'll watch into it and return if I find something.

  23. github-actions commented on May 19, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 14 days with no response from the author. It will be closed in next 7 days if no further activity occurs from the issue author.

  24. added
    stale
    on May 19, 2026
  25. github-actions commented on May 27, 2026

    @github-actions
    Contributor

    This issue has been closed because it has not received response from the issue author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corekind:bugpending-responseprovider:celerystale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions