You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "sunank200 (via GitHub)" <gi...@apache.org> on 2025/07/15 20:15:48 UTC

[PR] Move state utilities from airflow.utils.state to airflow.sdk.definitions.state [airflow]

sunank200 opened a new pull request, #53387:
URL: https://github.com/apache/airflow/pull/53387

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   Move user-facing state utilities from airflow.utils.state to airflow.sdk.definitions.state as part of the AIP-72 server-client separation effort.
   
   closes: [#53386](https://github.com/apache/airflow/issues/53386)
   related: [#53385](https://github.com/apache/airflow/issues/53385)
   related: [#51671](https://github.com/apache/airflow/issues/51671)
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Move state utilities from airflow.utils.state to airflow.sdk.definitions.state [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2215599986


##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/calendar.py:
##########
@@ -21,7 +21,12 @@
 
 from pydantic import BaseModel
 
-from airflow.utils.state import DagRunState
+from airflow.version_compat import AIRFLOW_V_3_1_PLUS
+
+if AIRFLOW_V_3_1_PLUS:
+    from airflow.sdk.definitions.state import DagRunState
+else:
+    from airflow.utils.state import DagRunState  # type: ignore[no-redef]

Review Comment:
   Yeah, check for all parts of state.py though, some might be too trivial to move to relevant places



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor JobState enum across Airflow components [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2282411719


##########
airflow-core/src/airflow/jobs/job.py:
##########
@@ -41,7 +42,19 @@
 from airflow.utils.platform import getuser
 from airflow.utils.session import NEW_SESSION, create_session, provide_session
 from airflow.utils.sqlalchemy import UtcDateTime
-from airflow.utils.state import JobState
+
+
+class JobState(str, Enum):
+    """All possible states that a Job can be in."""
+
+    RUNNING = "running"
+    SUCCESS = "success"
+    RESTARTING = "restarting"
+    FAILED = "failed"
+
+    def __str__(self) -> str:
+        return self.value

Review Comment:
   Incomplete sentence, I meant:
   
   > Although `from airflow.jobs.job import Job`, JobState is a good place for that enum to live in, so you can repurpose this PR for that ONLY.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Move state utilities from airflow.utils.state to airflow.sdk.definitions.state [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2215125802


##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/calendar.py:
##########
@@ -21,7 +21,12 @@
 
 from pydantic import BaseModel
 
-from airflow.utils.state import DagRunState
+from airflow.version_compat import AIRFLOW_V_3_1_PLUS
+
+if AIRFLOW_V_3_1_PLUS:
+    from airflow.sdk.definitions.state import DagRunState
+else:
+    from airflow.utils.state import DagRunState  # type: ignore[no-redef]

Review Comment:
   This isn't correct. Core cannot have a version check for imports.
   
   We can also not import again from SDK into core, we end up with the same problem we have now.
   
   I'd suggest to investigate the usage patterns of different components of the state.py and move them to places where it makes sense. It might make sense to duplicate some of those across core + sdk. 
   
   But this module in general feels like a good candidate to stay in the `airflow-shared` library to me.
   cc @ashb



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor JobState enum across Airflow components [airflow]

Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2282319355


##########
task-sdk/src/airflow/sdk/api/datamodels/_generated.py:
##########
@@ -472,6 +472,13 @@ class TaskInstanceState(str, Enum):
     DEFERRED = "deferred"
 
 
+class JobState(str, Enum):
+    RUNNING = "running"
+    SUCCESS = "success"
+    RESTARTING = "restarting"
+    FAILED = "failed"

Review Comment:
   It is only used in test but not in task-sdk code at all. https://github.com/apache/airflow/blob/main/task-sdk/tests/task_sdk/definitions/test_secrets_masker.py#L360
   
   Removing this completely from task-sdk



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Move state utilities from airflow.utils.state to airflow.sdk.definitions.state [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2215536412


##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/calendar.py:
##########
@@ -21,7 +21,12 @@
 
 from pydantic import BaseModel
 
-from airflow.utils.state import DagRunState
+from airflow.version_compat import AIRFLOW_V_3_1_PLUS
+
+if AIRFLOW_V_3_1_PLUS:
+    from airflow.sdk.definitions.state import DagRunState
+else:
+    from airflow.utils.state import DagRunState  # type: ignore[no-redef]

Review Comment:
   This approach has a fundamental **circular dependency problem**.
   
   You cannot check for version compatibility within the same package you're checking for:
   
   ```python
   from airflow import __version__  # Importing airflow's version from within airflow itself
   AIRFLOW_V_3_1_PLUS = get_base_airflow_version_tuple() >= (3, 1, 0)
   ```
   
   This is like asking "Am I myself?" to decide who you are - it's a logical impossibility. When airflow-core imports from `airflow.version_compat`, it's trying to check its own version to decide what to import, which creates a circular reference.
   
   Version compatibility checks only make sense when checking for *external* dependencies, not when a package is trying to check its own version for internal import decisions.



##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/calendar.py:
##########
@@ -21,7 +21,12 @@
 
 from pydantic import BaseModel
 
-from airflow.utils.state import DagRunState
+from airflow.version_compat import AIRFLOW_V_3_1_PLUS
+
+if AIRFLOW_V_3_1_PLUS:
+    from airflow.sdk.definitions.state import DagRunState
+else:
+    from airflow.utils.state import DagRunState  # type: ignore[no-redef]

Review Comment:
   Yeah core should never have that anyway coz you can't check a different version of the X library within the X library itself :) 
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Move state utilities from airflow.utils.state to airflow.sdk.definitions.state [airflow]

Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2215592101


##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/calendar.py:
##########
@@ -21,7 +21,12 @@
 
 from pydantic import BaseModel
 
-from airflow.utils.state import DagRunState
+from airflow.version_compat import AIRFLOW_V_3_1_PLUS
+
+if AIRFLOW_V_3_1_PLUS:
+    from airflow.sdk.definitions.state import DagRunState
+else:
+    from airflow.utils.state import DagRunState  # type: ignore[no-redef]

Review Comment:
   That's right now when I see it. I will change this. My thought process was that `DagRunState` is also used in providers, and I missed that the core will always be on latest version.
   
   After discussion with Amogh, the state is a good candidate for `airflow-shared`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor JobState enum across Airflow components [airflow]

Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2282388258


##########
task-sdk/src/airflow/sdk/api/datamodels/_generated.py:
##########
@@ -472,6 +472,13 @@ class TaskInstanceState(str, Enum):
     DEFERRED = "deferred"
 
 
+class JobState(str, Enum):
+    RUNNING = "running"
+    SUCCESS = "success"
+    RESTARTING = "restarting"
+    FAILED = "failed"

Review Comment:
   Removed it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor JobState enum across Airflow components [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2282508787


##########
task-sdk/tests/task_sdk/definitions/test_secrets_masker.py:
##########
@@ -357,7 +357,6 @@ def __init__(self, required_arg):
         [
             (DagRunState.SUCCESS, "success"),
             (TaskInstanceState.FAILED, "failed"),
-            (JobState.RUNNING, "running"),

Review Comment:
   Yeah its fine to remove, couple of examples in the params anyways



##########
airflow-core/src/airflow/utils/state.py:
##########
@@ -20,18 +20,6 @@
 from enum import Enum
 
 
-class JobState(str, Enum):
-    """All possible states that a Job can be in."""
-
-    RUNNING = "running"
-    SUCCESS = "success"
-    RESTARTING = "restarting"
-    FAILED = "failed"
-
-    def __str__(self) -> str:
-        return self.value

Review Comment:
   Needs a compat shim in `utils/__init__.py`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor JobState enum across Airflow components [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #53387:
URL: https://github.com/apache/airflow/pull/53387


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor JobState enum across Airflow components [airflow]

Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2282582015


##########
airflow-core/src/airflow/utils/state.py:
##########
@@ -20,18 +20,6 @@
 from enum import Enum
 
 
-class JobState(str, Enum):
-    """All possible states that a Job can be in."""
-
-    RUNNING = "running"
-    SUCCESS = "success"
-    RESTARTING = "restarting"
-    FAILED = "failed"
-
-    def __str__(self) -> str:
-        return self.value

Review Comment:
   Added the compat



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor JobState enum across Airflow components [airflow]

Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2282243902


##########
airflow-core/src/airflow/jobs/job.py:
##########
@@ -41,7 +42,19 @@
 from airflow.utils.platform import getuser
 from airflow.utils.session import NEW_SESSION, create_session, provide_session
 from airflow.utils.sqlalchemy import UtcDateTime
-from airflow.utils.state import JobState
+
+
+class JobState(str, Enum):
+    """All possible states that a Job can be in."""
+
+    RUNNING = "running"
+    SUCCESS = "success"
+    RESTARTING = "restarting"
+    FAILED = "failed"
+
+    def __str__(self) -> str:
+        return self.value

Review Comment:
   You can have this path and reuse though as part of this PR.



##########
task-sdk/src/airflow/sdk/api/datamodels/_generated.py:
##########
@@ -472,6 +472,13 @@ class TaskInstanceState(str, Enum):
     DEFERRED = "deferred"
 
 
+class JobState(str, Enum):
+    RUNNING = "running"
+    SUCCESS = "success"
+    RESTARTING = "restarting"
+    FAILED = "failed"

Review Comment:
   `JobState` is only EVER relevant to scheduler / CLI for the jobs command. It is definitely not needed in the task SDK as it has nothing to do with DAG author experience.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactor JobState enum across Airflow components [airflow]

Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2275972764


##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/calendar.py:
##########
@@ -21,7 +21,12 @@
 
 from pydantic import BaseModel
 
-from airflow.utils.state import DagRunState
+from airflow.version_compat import AIRFLOW_V_3_1_PLUS
+
+if AIRFLOW_V_3_1_PLUS:
+    from airflow.sdk.definitions.state import DagRunState
+else:
+    from airflow.utils.state import DagRunState  # type: ignore[no-redef]

Review Comment:
   I have done the change



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Move state utilities from airflow.utils.state to airflow.sdk.definitions.state [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #53387:
URL: https://github.com/apache/airflow/pull/53387#discussion_r2215464785


##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/calendar.py:
##########
@@ -21,7 +21,12 @@
 
 from pydantic import BaseModel
 
-from airflow.utils.state import DagRunState
+from airflow.version_compat import AIRFLOW_V_3_1_PLUS
+
+if AIRFLOW_V_3_1_PLUS:
+    from airflow.sdk.definitions.state import DagRunState
+else:
+    from airflow.utils.state import DagRunState  # type: ignore[no-redef]

Review Comment:
   Yeah core should never have that anyway coz you can't check a different version of the X library within the X library itself :) 
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org