Skip to content

AttributeError: 'CeleryKubernetesExecutor' object has no attribute 'slots_occupied' #41525

Closed

Description

@LipuFei

Apache Airflow version

Other Airflow 2 version (please specify below)

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

2.10.0 Python 3.12

What happened?

UPDATE: I think the CeleryKubernetesExecutor class should inherit BaseExecutor instead of LoggingMixin. BaseExecutor has the slots_occupied method implemented.

I get an error in the scheduler when I use CeleryKubernetesExecutor. My Airflow installation is on Kubernetes with the official Helm chart.

/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py:143 FutureWarning: The config section [kubernetes] has been renamed to [kubernetes_executor]. Please update your `conf.get*` call to use the new name
[2024-08-16T11:55:08.527+0200] {executor_loader.py:254} INFO - Loaded executor: CeleryKubernetesExecutor
[2024-08-16T11:55:08.826+0200] {scheduler_job_runner.py:935} INFO - Starting the scheduler
[2024-08-16T11:55:08.827+0200] {scheduler_job_runner.py:942} INFO - Processing each file at most -1 times
[2024-08-16T11:55:08.828+0200] {ecs_executor.py:181} INFO - Loading Connection information
[2024-08-16T11:55:09.724+0200] {base.py:84} INFO - Retrieving connection 'aws_default'
[2024-08-16T11:55:11.322+0200] {executor_loader.py:254} INFO - Loaded executor: airflow.providers.amazon.aws.executors.ecs.AwsEcsExecutor
[2024-08-16T11:55:11.323+0200] {kubernetes_executor.py:287} INFO - Start Kubernetes executor
[2024-08-16T11:55:11.435+0200] {kubernetes_executor_utils.py:140} INFO - Event: and now my watch begins starting at resource_version: 0
[2024-08-16T11:55:11.623+0200] {kubernetes_executor.py:208} INFO - Found 0 queued task instances
[2024-08-16T11:55:11.625+0200] {ecs_executor.py:125} INFO - Starting ECS Executor and determining health...
[2024-08-16T11:55:12.119+0200] {ecs_executor.py:173} INFO - ECS Executor health check has succeeded.
[2024-08-16T11:55:12.120+0200] {scheduler_job_runner.py:1843} INFO - Adopting or resetting orphaned tasks for active dag runs
[2024-08-16T11:55:12.246+0200] {scheduler_job_runner.py:1001} ERROR - Exception when executing SchedulerJob._run_scheduler_loop
Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/jobs/scheduler_job_runner.py", line 984, in _execute
    self._run_scheduler_loop()
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/jobs/scheduler_job_runner.py", line 1121, in _run_scheduler_loop
    num_queued_tis = self._do_scheduling(session)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/jobs/scheduler_job_runner.py", line 1264, in _do_scheduling
    num_queued_tis = self._critical_section_enqueue_task_instances(session=session)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/jobs/scheduler_job_runner.py", line 718, in _critical_section_enqueue_task_instances
    num_occupied_slots = sum([executor.slots_occupied for executor in self.job.executors])
                              ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'CeleryKubernetesExecutor' object has no attribute 'slots_occupied'
[2024-08-16T11:55:12.330+0200] {kubernetes_executor.py:752} INFO - Shutting down Kubernetes executor
[2024-08-16T11:55:12.529+0200] {scheduler_job_runner.py:1014} INFO - Exited execute loop

What you think should happen instead?

No response

How to reproduce

Install Airflow with the official Helm chart with CeleryKubernetesExecutor and the scheduler container will raise this exception.

Operating System

Kubernetes, Linux

Versions of Apache Airflow Providers

No response

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

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 Aug 16, 2024
  2. added
    provider:cncf-kubernetes
    on Aug 16, 2024
  3. salam-abdul commented on Aug 16, 2024

    @salam-abdul

    I'm getting a related error message on Airflow 2.10 and Python 3.11
    AttributeError: 'LocalKubernetesExecutor' object has no attribute 'slots_occupied'

  4. added this to the Airflow 2.10.1 milestone on Aug 16, 2024
  5. potiuk commented on Aug 16, 2024

    @potiuk
    Member

    CC: @o-nikolas -> seems to be result of #40017

  6. o-nikolas commented on Aug 16, 2024

    @o-nikolas
    Contributor

    I'll look into fixing this issue But I encourage folks to use Multiple Executor Configuration instead of these old (and should be deprecated) hybrid executors. These are exactly the types of issues that arise from these statically combined executors, since they're full of bespoke logic and hard coupling.

    @potiuk what steps need to be followed for us to deprecate these old hybrid executors for airflow 3.0? Or is that not possible because they are in provider packages?

  7. potiuk commented on Aug 16, 2024

    @potiuk
    Member

    @potiuk what steps need to be followed for us to deprecate these old hybrid executors for airflow 3.0? Or is that not possible because they are in provider packages

    We can deprecate-with-warnings those and remove them from providers when the time comes (which might or might not be faster than getting rid of Airflow 2 support from those providers.

  8. zoid-w commented on Aug 19, 2024

    @zoid-w

    On a related note ; the current helm chart (1.15.0) does not yet support the hybrid executor approach introduced in airflow 2.10.0.

    In the helm chart there is a constraint on an ENUM of the "old" executors.
    Not sure what the best approach would be to validate the executor input (if possible) considering the possibility to specify your own custom executor.

  9. KulykDmytro commented on Sep 9, 2024

    @KulykDmytro
    Contributor

    @potiuk issue still exists on

    • Python 3.11
    • Airflow 2.10.1
  10. potiuk commented on Sep 9, 2024

    @potiuk
    Member

    Did you try with latest provider?

  11. potiuk commented on Sep 9, 2024

    @potiuk
    Member
  12. eladkal commented on Sep 10, 2024

    @eladkal
    Contributor

    @potiuk issue still exists on

    • Python 3.11
    • Airflow 2.10.1

    please specify version of Celery provider that you are using

  13. rickyzhang82 commented on Dec 16, 2024

    @rickyzhang82

    @potiuk ,

    I checked out the tag: 2.10.2 from airflow Git repo (commit 35087d7) and still ran into the same attribute error:

      File "/home/Ricky/sas-u-home/rizhan/repo/github/airflow/airflow/jobs/scheduler_job_runner.py", line 718, in <listcomp>
        num_occupied_slots = sum([executor.slots_occupied for executor in self.job.executors])
    AttributeError: 'SasKubernetesCeleryExecutor' object has no attribute 'slots_occupied'
    

    However, we didn't see the same issue from Airflow in our production build which pip from PyPi with 2.10.2 tag.

    The source code from PyPi is not the same even though pointing to 2.10.2

    The one from PyPi -- airflow/providers/celery/executors/celery_kubernetes_executor.py has the fix but it is not in the 2.10.2 release tag

    119     @property
    120     def slots_occupied(self):
    121         """Number of tasks this executor instance is currently managing."""
    122         return len(self.running) + len(self.queued_tasks)
    

    I wonder why?

  14. o-nikolas commented on Dec 16, 2024

    @o-nikolas
    Contributor

    I see the that class in this case is SasKubernetesCeleryExecutor, what is that? Is that a class you've created that subclasses from the existing KubernetesCeleryExecutor?

    I'm not entirely sure why the code is not in the repo tag, but you see it in pypi. But the fix is definitely pushed, I just double checked main. I don't do releases personally, so perhaps @eladkal or @potiuk would know?

    Also, I still encourage folks to stop using these old static hybrid executors and please use the new multiple executor configuration 😃

  15. eladkal commented on Dec 17, 2024

    @eladkal
    Contributor

    Providers are released separately and independently from Airflow core. #41602 was released in celery provider 3.8.1

  16. rickyzhang82 commented on Dec 17, 2024

    @rickyzhang82

    @eladkal,

    I followed the doc contributing-docs/07_local_virtualenv.rst to create my dev playpen. I ran the following

    pip install -e ".[devel,postgres,redis,celery,cncf-kubernetes]" --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-2.10.2/constraints-3.9.txt"
    

    It doesn't seem that my local playpen pick up the right version of the providers w.r.t 2.10.2 core.

    How would you make them matched?

  17. potiuk commented on Dec 17, 2024

    @potiuk
    Member

    How would you make them matched?

    You can't have them from a single checkout - it's impossible. As also explained in another discussion (and abobe by @eladkal) providers and airflow are released separately - and our cotributor guide assumes you are working on main where you are working on latest airflow + latest providers at the same time.

    I am not sure that trying to have one devplay with the different versions of providers and airflow installed from sources is even something that makes sense for historical version because you are talking about potentially cross-matching and installing sources from different tags - with might or miugh not work.

    As explained elsewhere - tis will be easier once we implement #44511 - but until then you can try to - for example - install airflow in non editable mode, and then prepare the sources of the provider in the version you want by checking out the tag you want - look at the tags we have starting with providers-* and using breeze release-management prepare-provider-packages YOUR_PROVIDER --skip-deleting-generated-files - that will generate you the source folder structure (including pyproject.toml which you will be able to install your provider in the right version in --editable mode - additionally to airflow installed there.

    That's one of the ways how you can achieve it.

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:bugneeds-triageprovider:cncf-kubernetes

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions