You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/12/01 13:52:35 UTC

[GitHub] [airflow] ephraimbuddy opened a new pull request #19931: Deprecate some functions in the experimental API

ephraimbuddy opened a new pull request #19931:
URL: https://github.com/apache/airflow/pull/19931


   This PR seeks to deprecate some functions in the experimental API.
   Some of the deprecated functions are only used in the experimental REST API,
   others that are valid are being moved out of the experimental package.
   
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+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 [UPDATING.md](https://github.com/apache/airflow/blob/main/UPDATING.md).
   


-- 
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



[GitHub] [airflow] ashb commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r768643654



##########
File path: airflow/models/pool.py
##########
@@ -78,6 +86,54 @@ def get_default_pool(session: Session = None):
         """
         return Pool.get_pool(Pool.DEFAULT_POOL_NAME, session=session)
 
+    @staticmethod
+    @provide_session
+    def create_or_update_pool(name, slots, description, session=None):

Review comment:
       Let's use the new style now:
   
   ```suggestion
       def create_or_update_pool(name, slots, description, session=NEW_SESSION):
   ```




-- 
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



[GitHub] [airflow] uranusjr commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r763678681



##########
File path: airflow/api/common/delete_dag.py
##########
@@ -0,0 +1,82 @@
+#
+# 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.
+"""Delete DAGs APIs."""
+import logging
+
+from sqlalchemy import or_
+
+from airflow import models
+from airflow.exceptions import AirflowException, DagNotFound
+from airflow.models import DagModel, TaskFail
+from airflow.models.serialized_dag import SerializedDagModel
+from airflow.utils.session import provide_session
+from airflow.utils.state import State
+
+log = logging.getLogger(__name__)
+
+
+@provide_session
+def delete_dag(dag_id: str, keep_records_in_log: bool = True, session=None) -> int:
+    """
+    :param dag_id: the dag_id of the DAG to delete
+    :param keep_records_in_log: whether keep records of the given dag_id
+        in the Log table in the backend database (for reasons like auditing).
+        The default value is True.
+    :param session: session used
+    :return count of deleted dags
+    """
+    log.info("Deleting DAG: %s", dag_id)
+    running_tis = (
+        session.query(models.TaskInstance.state)
+        .filter(models.TaskInstance.dag_id == dag_id)
+        .filter(models.TaskInstance.state == State.RUNNING)
+        .first()
+    )
+    if running_tis:
+        raise AirflowException("TaskInstances still running")
+    dag = session.query(DagModel).filter(DagModel.dag_id == dag_id).first()
+    if dag is None:
+        raise DagNotFound(f"Dag id {dag_id} not found")
+
+    # Scheduler removes DAGs without files from serialized_dag table every dag_dir_list_interval.
+    # There may be a lag, so explicitly removes serialized DAG here.
+    if SerializedDagModel.has_dag(dag_id=dag_id, session=session):
+        SerializedDagModel.remove_dag(dag_id=dag_id, session=session)
+
+    count = 0
+
+    for model in models.base.Base._decl_class_registry.values():

Review comment:
       May be a good chance to fix this as well
   
   https://github.com/apache/airflow/issues/15354#issuecomment-987388275




-- 
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



[GitHub] [airflow] ashb commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r768644374



##########
File path: airflow/models/pool.py
##########
@@ -78,6 +86,54 @@ def get_default_pool(session: Session = None):
         """
         return Pool.get_pool(Pool.DEFAULT_POOL_NAME, session=session)
 
+    @staticmethod
+    @provide_session
+    def create_or_update_pool(name, slots, description, session=None):
+        """Create a pool with given parameters or update it if it already exists."""
+        if not (name and name.strip()):
+            raise AirflowBadRequest("Pool name shouldn't be empty")
+        try:
+            slots = int(slots)
+        except ValueError:
+            raise AirflowBadRequest(f"Bad value for `slots`: {slots}")
+
+        # Get the length of the pool column
+        pool_name_length = Pool.pool.property.columns[0].type.length
+        if len(name) > pool_name_length:
+            raise AirflowBadRequest(f"Pool name can't be more than {pool_name_length} characters")
+
+        session.expire_on_commit = False
+        pool = session.query(Pool).filter_by(pool=name).first()
+        if pool is None:
+            pool = Pool(pool=name, slots=slots, description=description)
+            session.add(pool)
+        else:
+            pool.slots = slots
+            pool.description = description
+
+        session.commit()
+
+        return pool
+
+    @staticmethod
+    @provide_session
+    def delete_pool(name, session=None):
+        """Delete pool by a given name."""
+        if not (name and name.strip()):
+            raise AirflowBadRequest("Pool name shouldn't be empty")

Review comment:
       If this is living in models this is the wrong exception to throw. Also this validation really belongs in the API, not in the model.




-- 
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



[GitHub] [airflow] ephraimbuddy commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r760395447



##########
File path: tests/models/test_pool.py
##########
@@ -15,27 +15,51 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+import random
+import string
+
+import pytest
 
 from airflow import settings
+from airflow.exceptions import AirflowBadRequest, PoolNotFound
 from airflow.models.pool import Pool
 from airflow.models.taskinstance import TaskInstance as TI
 from airflow.operators.dummy import DummyOperator
 from airflow.utils import timezone
+from airflow.utils.session import create_session
 from airflow.utils.state import State
 from tests.test_utils.db import clear_db_dags, clear_db_pools, clear_db_runs, set_default_pool_slots
 
 DEFAULT_DATE = timezone.datetime(2016, 1, 1)
 
 
 class TestPool:
+
+    USER_POOL_COUNT = 2
+    TOTAL_POOL_COUNT = USER_POOL_COUNT + 1  # including default_pool
+
     @staticmethod
     def clean_db():
         clear_db_dags()
         clear_db_runs()
         clear_db_pools()
 
-    def setup_method(self):
+    def setup_method(self, session):

Review comment:
       ```suggestion
       def setup_method(self):
   ```




-- 
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



[GitHub] [airflow] uranusjr commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r763819460



##########
File path: airflow/api/client/local_client.py
##########
@@ -36,18 +38,20 @@ def delete_dag(self, dag_id):
         return f"Removed {count} record(s)"
 
     def get_pool(self, name):
-        the_pool = pool.get_pool(name=name)
+        the_pool = Pool.get_pool(pool_name=name)

Review comment:
       Since we’re no longer importing a module named `pool`, let’s change this variable to `pool` which is much prettier than `the_pool`.




-- 
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



[GitHub] [airflow] uranusjr commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r763820517



##########
File path: airflow/api/common/delete_dag.py
##########
@@ -0,0 +1,87 @@
+#
+# 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.
+"""Delete DAGs APIs."""
+import logging
+
+from sqlalchemy import or_
+
+from airflow import models
+from airflow.exceptions import AirflowException, DagNotFound
+from airflow.models import DagModel, TaskFail
+from airflow.models.serialized_dag import SerializedDagModel
+from airflow.utils.session import provide_session
+from airflow.utils.state import State
+
+log = logging.getLogger(__name__)
+
+
+@provide_session
+def delete_dag(dag_id: str, keep_records_in_log: bool = True, session=None) -> int:
+    """
+    :param dag_id: the dag_id of the DAG to delete
+    :param keep_records_in_log: whether keep records of the given dag_id
+        in the Log table in the backend database (for reasons like auditing).
+        The default value is True.
+    :param session: session used
+    :return count of deleted dags
+    """
+    log.info("Deleting DAG: %s", dag_id)
+    running_tis = (
+        session.query(models.TaskInstance.state)
+        .filter(models.TaskInstance.dag_id == dag_id)
+        .filter(models.TaskInstance.state == State.RUNNING)
+        .first()
+    )
+    if running_tis:
+        raise AirflowException("TaskInstances still running")
+    dag = session.query(DagModel).filter(DagModel.dag_id == dag_id).first()
+    if dag is None:
+        raise DagNotFound(f"Dag id {dag_id} not found")
+
+    # Scheduler removes DAGs without files from serialized_dag table every dag_dir_list_interval.
+    # There may be a lag, so explicitly removes serialized DAG here.
+    if SerializedDagModel.has_dag(dag_id=dag_id, session=session):
+        SerializedDagModel.remove_dag(dag_id=dag_id, session=session)
+
+    count = 0
+
+    try:
+        models_ = [mapper.class_ for mapper in models.base.Base.registry.mappers]
+    except AttributeError:
+        models_ = models.base.Base._decl_class_registry.values()

Review comment:
       Might be worthwhile to put this somewhere in `airflow.utils` with a docstring explaining why it’s needed.




-- 
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



[GitHub] [airflow] uranusjr commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r763821844



##########
File path: airflow/api/client/local_client.py
##########
@@ -36,18 +38,20 @@ def delete_dag(self, dag_id):
         return f"Removed {count} record(s)"
 
     def get_pool(self, name):
-        the_pool = pool.get_pool(name=name)
+        the_pool = Pool.get_pool(pool_name=name)
+        if not the_pool:
+            raise PoolNotFound(f"Pool {name} not found")

Review comment:
       Looking at where this function is being called, I wonder if we should just get rid of this exception altogether and just return `Optional[Pool]`.




-- 
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



[GitHub] [airflow] uranusjr commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r763806798



##########
File path: airflow/api/common/delete_dag.py
##########
@@ -0,0 +1,87 @@
+#
+# 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.
+"""Delete DAGs APIs."""
+import logging
+
+from sqlalchemy import or_
+
+from airflow import models
+from airflow.exceptions import AirflowException, DagNotFound
+from airflow.models import DagModel, TaskFail
+from airflow.models.serialized_dag import SerializedDagModel
+from airflow.utils.session import provide_session
+from airflow.utils.state import State
+
+log = logging.getLogger(__name__)
+
+
+@provide_session
+def delete_dag(dag_id: str, keep_records_in_log: bool = True, session=None) -> int:
+    """
+    :param dag_id: the dag_id of the DAG to delete
+    :param keep_records_in_log: whether keep records of the given dag_id
+        in the Log table in the backend database (for reasons like auditing).
+        The default value is True.
+    :param session: session used
+    :return count of deleted dags
+    """
+    log.info("Deleting DAG: %s", dag_id)
+    running_tis = (
+        session.query(models.TaskInstance.state)
+        .filter(models.TaskInstance.dag_id == dag_id)
+        .filter(models.TaskInstance.state == State.RUNNING)
+        .first()
+    )
+    if running_tis:
+        raise AirflowException("TaskInstances still running")
+    dag = session.query(DagModel).filter(DagModel.dag_id == dag_id).first()
+    if dag is None:
+        raise DagNotFound(f"Dag id {dag_id} not found")
+
+    # Scheduler removes DAGs without files from serialized_dag table every dag_dir_list_interval.
+    # There may be a lag, so explicitly removes serialized DAG here.
+    if SerializedDagModel.has_dag(dag_id=dag_id, session=session):
+        SerializedDagModel.remove_dag(dag_id=dag_id, session=session)
+
+    count = 0
+
+    try:
+        models_ = models.base.Base._decl_class_registry.values()
+    except AttributeError:
+        models_ = [mapper.class_ for mapper in models.base.Base.registry.mappers]
+

Review comment:
       Maybe we should flip the blocks (try `Base.registry` first and fall back to `_decl_class_registry`) since `registry` is a promised public API, and we don’t know if `_decl_class_registry` would change _again_ in the future.




-- 
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



[GitHub] [airflow] ephraimbuddy commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r768705442



##########
File path: airflow/models/pool.py
##########
@@ -78,6 +86,54 @@ def get_default_pool(session: Session = None):
         """
         return Pool.get_pool(Pool.DEFAULT_POOL_NAME, session=session)
 
+    @staticmethod
+    @provide_session
+    def create_or_update_pool(name, slots, description, session=None):
+        """Create a pool with given parameters or update it if it already exists."""
+        if not (name and name.strip()):
+            raise AirflowBadRequest("Pool name shouldn't be empty")
+        try:
+            slots = int(slots)
+        except ValueError:
+            raise AirflowBadRequest(f"Bad value for `slots`: {slots}")
+
+        # Get the length of the pool column
+        pool_name_length = Pool.pool.property.columns[0].type.length
+        if len(name) > pool_name_length:
+            raise AirflowBadRequest(f"Pool name can't be more than {pool_name_length} characters")
+
+        session.expire_on_commit = False
+        pool = session.query(Pool).filter_by(pool=name).first()
+        if pool is None:
+            pool = Pool(pool=name, slots=slots, description=description)
+            session.add(pool)
+        else:
+            pool.slots = slots
+            pool.description = description
+
+        session.commit()
+
+        return pool
+
+    @staticmethod
+    @provide_session
+    def delete_pool(name, session=None):
+        """Delete pool by a given name."""
+        if not (name and name.strip()):
+            raise AirflowBadRequest("Pool name shouldn't be empty")

Review comment:
       I will address 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



[GitHub] [airflow] uranusjr commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r763821844



##########
File path: airflow/api/client/local_client.py
##########
@@ -36,18 +38,20 @@ def delete_dag(self, dag_id):
         return f"Removed {count} record(s)"
 
     def get_pool(self, name):
-        the_pool = pool.get_pool(name=name)
+        the_pool = Pool.get_pool(pool_name=name)
+        if not the_pool:
+            raise PoolNotFound(f"Pool {name} not found")

Review comment:
       Looking at where this function is being called, I wonder if we should just get rid of this exception altogether and just return `Optional`. Not sure about this.




-- 
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



[GitHub] [airflow] ashb commented on pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ashb commented on pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#issuecomment-987846507


   > > Shouldn't we delete `airflow/api/common/experimental/delete_dag.py` etc as part of this PR too?
   > 
   > I was of the opinion that it's a public API and want to deprecate it first and remove it in 2.3.0 but if it's not, I can remove it. Let me know if I should go-ahead
   
   Yes, good point. Use the same approach as I mention here https://github.com/apache/airflow/pull/18724#discussion_r763907624


-- 
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



[GitHub] [airflow] ephraimbuddy commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r763810461



##########
File path: airflow/api/common/delete_dag.py
##########
@@ -0,0 +1,87 @@
+#
+# 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.
+"""Delete DAGs APIs."""
+import logging
+
+from sqlalchemy import or_
+
+from airflow import models
+from airflow.exceptions import AirflowException, DagNotFound
+from airflow.models import DagModel, TaskFail
+from airflow.models.serialized_dag import SerializedDagModel
+from airflow.utils.session import provide_session
+from airflow.utils.state import State
+
+log = logging.getLogger(__name__)
+
+
+@provide_session
+def delete_dag(dag_id: str, keep_records_in_log: bool = True, session=None) -> int:
+    """
+    :param dag_id: the dag_id of the DAG to delete
+    :param keep_records_in_log: whether keep records of the given dag_id
+        in the Log table in the backend database (for reasons like auditing).
+        The default value is True.
+    :param session: session used
+    :return count of deleted dags
+    """
+    log.info("Deleting DAG: %s", dag_id)
+    running_tis = (
+        session.query(models.TaskInstance.state)
+        .filter(models.TaskInstance.dag_id == dag_id)
+        .filter(models.TaskInstance.state == State.RUNNING)
+        .first()
+    )
+    if running_tis:
+        raise AirflowException("TaskInstances still running")
+    dag = session.query(DagModel).filter(DagModel.dag_id == dag_id).first()
+    if dag is None:
+        raise DagNotFound(f"Dag id {dag_id} not found")
+
+    # Scheduler removes DAGs without files from serialized_dag table every dag_dir_list_interval.
+    # There may be a lag, so explicitly removes serialized DAG here.
+    if SerializedDagModel.has_dag(dag_id=dag_id, session=session):
+        SerializedDagModel.remove_dag(dag_id=dag_id, session=session)
+
+    count = 0
+
+    try:
+        models_ = models.base.Base._decl_class_registry.values()
+    except AttributeError:
+        models_ = [mapper.class_ for mapper in models.base.Base.registry.mappers]
+

Review comment:
       Ok




-- 
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



[GitHub] [airflow] github-actions[bot] commented on pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#issuecomment-994510747


   The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.


-- 
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



[GitHub] [airflow] ephraimbuddy commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r768704551



##########
File path: airflow/api/common/experimental/get_dag_run_state.py
##########
@@ -19,9 +19,12 @@
 from datetime import datetime
 from typing import Dict
 
+from deprecated import deprecated
+
 from airflow.api.common.experimental import check_and_get_dag, check_and_get_dagrun
 
 
+@deprecated(reason="Use DagRun().get_state() instead", version="2.2.3")

Review comment:
       The experimental API is also deprecated: See https://github.com/apache/airflow/blob/b20e6d3f060bc385e350433070d5707ae6d6d0b0/airflow/www/api/experimental/endpoints.py#L56-L60.
   
   My thinking is that if someone is using it externally which may be possible, then we should warn




-- 
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



[GitHub] [airflow] ephraimbuddy merged pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ephraimbuddy merged pull request #19931:
URL: https://github.com/apache/airflow/pull/19931


   


-- 
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



[GitHub] [airflow] ashb commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r768642495



##########
File path: airflow/api/common/experimental/get_dag_run_state.py
##########
@@ -19,9 +19,12 @@
 from datetime import datetime
 from typing import Dict
 
+from deprecated import deprecated
+
 from airflow.api.common.experimental import check_and_get_dag, check_and_get_dagrun
 
 
+@deprecated(reason="Use DagRun().get_state() instead", version="2.2.3")

Review comment:
       This is still used in airflow/www/api/experimental/endpoints.py -- if we are deprecating it we will need to change those references too.




-- 
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



[GitHub] [airflow] ephraimbuddy commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r760393787



##########
File path: airflow/api/client/local_client.py
##########
@@ -36,18 +38,20 @@ def delete_dag(self, dag_id):
         return f"Removed {count} record(s)"
 
     def get_pool(self, name):
-        the_pool = pool.get_pool(name=name)
+        the_pool = Pool.get_pool(pool_name=name)
+        if not the_pool:
+            raise PoolNotFound(f"Pool {name} not found")

Review comment:
       Previously, the `get_pool` experimental API raises PoolNotFound when the pool does not exist. Since I have moved it to the Pool model, I don't want it to raise hence raising not found here




-- 
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



[GitHub] [airflow] ashb commented on a change in pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#discussion_r763885439



##########
File path: airflow/api/common/delete_dag.py
##########
@@ -0,0 +1,87 @@
+#
+# 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.
+"""Delete DAGs APIs."""
+import logging
+
+from sqlalchemy import or_
+
+from airflow import models
+from airflow.exceptions import AirflowException, DagNotFound
+from airflow.models import DagModel, TaskFail
+from airflow.models.serialized_dag import SerializedDagModel
+from airflow.utils.session import provide_session
+from airflow.utils.state import State
+
+log = logging.getLogger(__name__)
+
+
+@provide_session
+def delete_dag(dag_id: str, keep_records_in_log: bool = True, session=None) -> int:
+    """
+    :param dag_id: the dag_id of the DAG to delete
+    :param keep_records_in_log: whether keep records of the given dag_id
+        in the Log table in the backend database (for reasons like auditing).
+        The default value is True.
+    :param session: session used
+    :return count of deleted dags
+    """
+    log.info("Deleting DAG: %s", dag_id)
+    running_tis = (
+        session.query(models.TaskInstance.state)
+        .filter(models.TaskInstance.dag_id == dag_id)
+        .filter(models.TaskInstance.state == State.RUNNING)
+        .first()
+    )
+    if running_tis:
+        raise AirflowException("TaskInstances still running")
+    dag = session.query(DagModel).filter(DagModel.dag_id == dag_id).first()
+    if dag is None:
+        raise DagNotFound(f"Dag id {dag_id} not found")
+
+    # Scheduler removes DAGs without files from serialized_dag table every dag_dir_list_interval.
+    # There may be a lag, so explicitly removes serialized DAG here.
+    if SerializedDagModel.has_dag(dag_id=dag_id, session=session):
+        SerializedDagModel.remove_dag(dag_id=dag_id, session=session)
+
+    count = 0
+
+    try:
+        models_ = [mapper.class_ for mapper in models.base.Base.registry.mappers]
+    except AttributeError:
+        models_ = models.base.Base._decl_class_registry.values()

Review comment:
       Is this still needed? It was probably a work around for not having SQLA relationships defined.
   
   (I guess we still don't have all of them defined)




-- 
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



[GitHub] [airflow] ephraimbuddy commented on pull request #19931: Deprecate some functions in the experimental API

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on pull request #19931:
URL: https://github.com/apache/airflow/pull/19931#issuecomment-987838220


   > Shouldn't we delete `airflow/api/common/experimental/delete_dag.py` etc as part of this PR too?
   
   I was of the opinion that it's a public API and want to deprecate it first and remove it in 2.3.0 but if it's not, I can remove it. Let me know if I should go-ahead


-- 
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