You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "rickychen-infinirc (via GitHub)" <gi...@apache.org> on 2025/12/30 02:22:48 UTC

[PR] Refactor airflow-core/src to use SQLA2 [airflow]

rickychen-infinirc opened a new pull request, #59918:
URL: https://github.com/apache/airflow/pull/59918

   related: #59402
   
   Migrate deprecated SQLAlchemy Query object usage to SQLAlchemy 2.0 style in:
   - `airflow-core/src/airflow/dag_processing/bundles/manager.py`
   - `airflow-core/src/airflow/migrations/versions/0015_2_9_0_update_trigger_kwargs_type.py`
   - `airflow-core/src/airflow/utils/db_cleanup.py`
   
   ---
   ^ Add meaningful description above
   Read the Pull Request Guidelines for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
   In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
   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.
   
   


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700658277


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   Yes ! You are right !! but what if  - (It's just my thought)
   
   ```
   statement =  select(Log).where(
               Log.task_id == ti.task_id,
               Log.dag_id == ti.dag_id,
               Log.run_id == ti.run_id,
               Log.map_index == ti.map_index,
               Log.try_number == ti.try_number,
               Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
   
   ```
   and we can use `func.count` in `count_result`  like `session.scalar(select(func.count(statement)).select_from(Log)`
   
   I apologize if I created any confusion 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


Re: [PR] Refactor airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700673447


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   Thanks !! 
   
   I need to deep dive into this and then get back to you  



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "rickychen-infinirc (via GitHub)" <gi...@apache.org>.
rickychen-infinirc commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3703211703

   @potiuk CI is failing on ERD diagram edge ordering again after rebasing. The code changes are complete - could you help resolve this? Thanks!


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700658277


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   Yes ! You are right !! but what if  - (It's just my thought)
   
   statement =  select(Log).where(
               Log.task_id == ti.task_id,
               Log.dag_id == ti.dag_id,
               Log.run_id == ti.run_id,
               Log.map_index == ti.map_index,
               Log.try_number == ti.try_number,
               Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
   
   and we use `func.count` in `count_result`  like session.scalar(select(func.count(statement)).select_from(Log)
   
   I apologize if I created any confusion 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


Re: [PR] Refactor airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2689947393


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########


Review Comment:
   (I missed this earlier) -  Do we need to remove` session()` from here, since we are not using ? 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700600205


##########
.pre-commit-config.yaml:
##########


Review Comment:
   Great !! 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3707755244

   Static checks are failing !! Could you please fix them ? 


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700593686


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   This also works fine but we can also customize it to use only `select()` and not `func.count()` here since above query is not using this and we applied it in `count_result `
   
   What do you think ? 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "rickychen-infinirc (via GitHub)" <gi...@apache.org>.
rickychen-infinirc commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2661017732


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -183,17 +184,17 @@ def readable_config(self):
 config_dict: dict[str, _TableConfig] = {x.orm_model.name: x for x in sorted(config_list)}
 
 
-def _check_for_rows(*, query: Query, print_rows: bool = False) -> int:
-    num_entities = query.count()
+def _check_for_rows(*, query: Select, print_rows: bool = False, session: Session) -> int:

Review Comment:
   Good point! Renamed `query` to `statement` in `_check_for_rows` and `_do_delete` for consistency with SQLAlchemy 2.0 terminology. Thanks!



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2659420769


##########
.pre-commit-config.yaml:
##########
@@ -424,6 +424,9 @@ repos:
             (?x)
             ^airflow-ctl.*\.py$|
             ^airflow-core/src/airflow/models/.*\.py$|
+            ^airflow-core/src/airflow/dag_processing/.*\.py$|
+            ^airflow-core/src/airflow/migrations/.*\.py$|

Review Comment:
   It seems like this file was added by mistake



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3762686253

   > OOPS Conflict !!
   > 
   > I believe the deprecated query part was removed from `airflow-core/src/airflow/utils/db_cleanup.py` and has already been merged - PR - #60377
   
   Reverted to upstream version from PR #60377 to avoid conflict. 


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2667972334


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -223,8 +224,10 @@ def _do_delete(
     batch_counter = itertools.count(1)
 
     while True:
-        limited_query = query.limit(batch_size) if batch_size else query
-        if limited_query.count() == 0:  # nothing left to delete
+        limited_statement = statement.limit(batch_size) if batch_size else statement
+        if (
+            session.execute(select(func.count()).select_from(limited_statement.subquery())).scalar() or 0
+        ) == 0:

Review Comment:
   Yeah, that makes sense.
   Using session.scalar(...) or 0 is simpler and reads better here.
   I’ve updated it accordingly.



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "rickychen-infinirc (via GitHub)" <gi...@apache.org>.
rickychen-infinirc commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3707760276

   > Static checks are failing !! Could you please fix them ?
   
   OK, I’ll check it later and get back to you. Thanks!


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3749031392

   It would be good if @ephraimbuddy could review this — I learned some imp` SQLAlchemy 2.0` rules from him 
   
   Let's learn more !! 


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2667880573


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -223,8 +224,10 @@ def _do_delete(
     batch_counter = itertools.count(1)
 
     while True:
-        limited_query = query.limit(batch_size) if batch_size else query
-        if limited_query.count() == 0:  # nothing left to delete
+        limited_statement = statement.limit(batch_size) if batch_size else statement
+        if (
+            session.execute(select(func.count()).select_from(limited_statement.subquery())).scalar() or 0
+        ) == 0:

Review Comment:
   What if we directly use `(session.scalar() or 0)` ? (It's just my point of view)
   
   Could you please share your thoughts on 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


Re: [PR] Refactor airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2668471874


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -332,10 +333,10 @@ def _build_query(
     dag_ids: list[str] | None = None,
     exclude_dag_ids: list[str] | None = None,
     **kwargs,
-) -> Query:
+) -> Select:
     base_table_alias = "base"
     base_table = aliased(orm_model, name=base_table_alias)
-    query = session.query(base_table).with_entities(text(f"{base_table_alias}.*"))
+    query = select(text(f"{base_table_alias}.*")).select_from(base_table)

Review Comment:
   Do we need to rename this query ?  



-- 
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 airflow-core/src to use SQLA2 [airflow]

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


##########
.pre-commit-config.yaml:
##########


Review Comment:
   If the full Airflow-Core is now clean, can you shrink the list down here to just `^airflow-core/.*.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 airflow-core/src to use SQLA2 [airflow]

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


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -183,17 +184,17 @@ def readable_config(self):
 config_dict: dict[str, _TableConfig] = {x.orm_model.name: x for x in sorted(config_list)}
 
 
-def _check_for_rows(*, query: Query, print_rows: bool = False) -> int:
-    num_entities = query.count()
+def _check_for_rows(*, query: Select, print_rows: bool = False, session: Session) -> int:

Review Comment:
   Should query be renamed to statement(select_stmt) 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


Re: [PR] Refactor airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700596985


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -224,10 +224,8 @@ def _do_delete(
     batch_counter = itertools.count(1)
 
     while True:
-        limited_query = query.limit(batch_size) if batch_size else query
-        if (
-            session.scalars(select(func.count()).select_from(limited_query.subquery())).one() == 0
-        ):  # nothing left to delete

Review Comment:
   It's also good to add this comment in the` if` statement as it is 
   
   WDYT ? 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700658277


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   Yes ! You are right !! but what if  - (It's just my thought)
   
   statement =  select(Log).where(
               Log.task_id == ti.task_id,
               Log.dag_id == ti.dag_id,
               Log.run_id == ti.run_id,
               Log.map_index == ti.map_index,
               Log.try_number == ti.try_number,
               Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
   
   and we can use `func.count` in `count_result`  like session.scalar(select(func.count(statement)).select_from(Log)
   
   I apologize if I created any confusion 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


Re: [PR] Refactor airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700693841


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   Yes, you are right! This is the simplest and best approach.
   And if we follow that approach, we might need to use `.subquery()`, which will make it more complex
   
   Thanks a lot, I learned a lot from this discussion. 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700668485


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   Thanks for the suggestion! I tested both approaches:
   Current approach:
   ```select(func.count()).select_from(Log).where(...)```
   Generates:
   ```SELECT count(*) FROM log WHERE ...```
   
   Separated approach:
   ```
   statement = select(Log).where(...)
   select(func.count(statement)).select_from(Log)
   ```
   Generates:
   ```SELECT count((SELECT log.id, log.task_id FROM log WHERE ...)) FROM log```
   
   This triggers a SQLAlchemy warning about implicit coercion and produces unexpected SQL.
   
   The current approach generates the cleanest and most efficient query. What do you think? Please correct me if I'm wrong.



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2667880573


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -223,8 +224,10 @@ def _do_delete(
     batch_counter = itertools.count(1)
 
     while True:
-        limited_query = query.limit(batch_size) if batch_size else query
-        if limited_query.count() == 0:  # nothing left to delete
+        limited_statement = statement.limit(batch_size) if batch_size else statement
+        if (
+            session.execute(select(func.count()).select_from(limited_statement.subquery())).scalar() or 0
+        ) == 0:

Review Comment:
   What if we directly use (session.scalar() or 0) ? 
   
   Could you please share your thoughts on 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


Re: [PR] Refactor airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3758566966

   > LGTM
   > 
   > Can you run the command with test data to confirm the functionality?
   
   ```
   rickychen@airflow-dev:~/Desktop/airflow/airflow$ airflow db migrate           
   2026-01-16T07:31:07.753754Z [info     ] setup plugin alembic.autogenerate.schemas [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:31:07.753981Z [info     ] setup plugin alembic.autogenerate.tables [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:31:07.754136Z [info     ] setup plugin alembic.autogenerate.types [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:31:07.754253Z [info     ] setup plugin alembic.autogenerate.constraints [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:31:07.754362Z [info     ] setup plugin alembic.autogenerate.defaults [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:31:07.754469Z [info     ] setup plugin alembic.autogenerate.comments [alembic.runtime.plugins] loc=plugins.py:37
   DB: sqlite:////home/rickychen/airflow/airflow.db
   Performing upgrade to the metadata database sqlite:////home/rickychen/airflow/airflow.db
   2026-01-16T07:31:08.888657Z [info     ] Context impl SQLiteImpl.       [alembic.runtime.migration] loc=migration.py:210
   2026-01-16T07:31:08.888864Z [info     ] Will assume non-transactional DDL. [alembic.runtime.migration] loc=migration.py:213
   2026-01-16T07:31:08.891245Z [info     ] Migrating the Airflow database [airflow.utils.db] loc=db.py:1129
   2026-01-16T07:31:08.896066Z [info     ] Context impl SQLiteImpl.       [alembic.runtime.migration] loc=migration.py:210
   2026-01-16T07:31:08.896213Z [info     ] Will assume non-transactional DDL. [alembic.runtime.migration] loc=migration.py:213
   2026-01-16T07:31:08.923112Z [info     ] Context impl SQLiteImpl.       [alembic.runtime.migration] loc=migration.py:210
   2026-01-16T07:31:08.923245Z [info     ] Will assume non-transactional DDL. [alembic.runtime.migration] loc=migration.py:213
   Database migrating done!
   rickychen@airflow-dev:~/Desktop/airflow/airflow$ airflow db clean --dry-run --clean-before-timestamp "2026-01-01"
   2026-01-16T07:31:17.493968Z [info     ] setup plugin alembic.autogenerate.schemas [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:31:17.494237Z [info     ] setup plugin alembic.autogenerate.tables [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:31:17.494393Z [info     ] setup plugin alembic.autogenerate.types [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:31:17.494528Z [info     ] setup plugin alembic.autogenerate.constraints [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:31:17.494689Z [info     ] setup plugin alembic.autogenerate.defaults [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:31:17.494804Z [info     ] setup plugin alembic.autogenerate.comments [alembic.runtime.plugins] loc=plugins.py:37
   Performing dry run for db cleanup.
   Data prior to 2026-01-01 00:00:00+00:00 would be purged from tables ['callback_request', '_xcom_archive', 'task_reschedule', 'task_instance_history', 'xcom', 'task_instance', 'deadline', 'dag_run', 'dag_version', 'trigger', 'dag', 'celery_tasksetmeta', 'log', 'celery_taskmeta', 'import_error', 'asset_event', 'sla_miss', 'job'] with the following config:
   
   table              | recency_column     | keep_last | keep_last_filters | keep_last_group_by
   ===================+====================+===========+===================+===================
   callback_request   | callback_request.c | False     | None              | None              
                      | reated_at          |           |                   |                   
   _xcom_archive      | _xcom_archive.time | False     | None              | None              
                      | stamp              |           |                   |                   
   task_reschedule    | task_reschedule.st | False     | None              | None              
                      | art_date           |           |                   |                   
   task_instance_hist | task_instance_hist | False     | None              | None              
   ory                | ory.start_date     |           |                   |                   
   xcom               | xcom.timestamp     | False     | None              | None              
   task_instance      | task_instance.star | False     | None              | None              
                      | t_date             |           |                   |                   
   deadline           | deadline.deadline_ | False     | None              | None              
                      | time               |           |                   |                   
   dag_run            | dag_run.start_date | True      | ['run_type !=     | ['dag_id']        
                      |                    |           | :run_type_1']     |                   
   dag_version        | dag_version.create | False     | None              | None              
                      | d_at               |           |                   |                   
   trigger            | trigger.created_da | False     | None              | None              
                      | te                 |           |                   |                   
   dag                | dag.last_parsed_ti | False     | None              | None              
                      | me                 |           |                   |                   
   celery_tasksetmeta | celery_tasksetmeta | False     | None              | None              
                      | .date_done         |           |                   |                   
   log                | log.dttm           | False     | None              | None              
   celery_taskmeta    | celery_taskmeta.da | False     | None              | None              
                      | te_done            |           |                   |                   
   import_error       | import_error.times | False     | None              | None              
                      | tamp               |           |                   |                   
   asset_event        | asset_event.timest | False     | None              | None              
                      | amp                |           |                   |                   
   sla_miss           | sla_miss.timestamp | False     | None              | None              
   job                | job.latest_heartbe | False     | None              | None              
                      | at                 |           |                   |                   
                                                                                               
   
   Performing dry run for table callback_request
   Checking table callback_request
   Found 0 rows meeting deletion criteria.
   2026-01-16T07:31:18.745211Z [warning  ] Table _xcom_archive not found.  Skipping. [airflow.utils.db_cleanup] loc=db_cleanup.py:552
   
   Performing dry run for table task_reschedule
   Checking table task_reschedule
   Found 0 rows meeting deletion criteria.
   
   Performing dry run for table task_instance_history
   Checking table task_instance_history
   Found 0 rows meeting deletion criteria.
   
   Performing dry run for table xcom
   Checking table xcom
   Found 0 rows meeting deletion criteria.
   
   Performing dry run for table task_instance
   Checking table task_instance
   Found 0 rows meeting deletion criteria.
   
   Performing dry run for table deadline
   Checking table deadline
   Found 0 rows meeting deletion criteria.
   
   Performing dry run for table dag_run
   Checking table dag_run
   Found 0 rows meeting deletion criteria.
   
   Performing dry run for table dag_version
   Checking table dag_version
   Found 0 rows meeting deletion criteria.
   
   Performing dry run for table trigger
   Checking table trigger
   Found 0 rows meeting deletion criteria.
   
   Performing dry run for table dag
   Checking table dag
   Found 0 rows meeting deletion criteria.
   2026-01-16T07:31:18.764759Z [warning  ] Table celery_tasksetmeta not found.  Skipping. [airflow.utils.db_cleanup] loc=db_cleanup.py:552
   
   Performing dry run for table log
   Checking table log
   Found 0 rows meeting deletion criteria.
   2026-01-16T07:31:18.766781Z [warning  ] Table celery_taskmeta not found.  Skipping. [airflow.utils.db_cleanup] loc=db_cleanup.py:552
   
   Performing dry run for table import_error
   Checking table import_error
   Found 0 rows meeting deletion criteria.
   
   Performing dry run for table asset_event
   Checking table asset_event
   Found 0 rows meeting deletion criteria.
   2026-01-16T07:31:18.770724Z [warning  ] Table sla_miss not found.  Skipping. [airflow.utils.db_cleanup] loc=db_cleanup.py:552
   
   Performing dry run for table job
   Checking table job
   Found 0 rows meeting deletion criteria.
   
   
   rickychen@airflow-dev:~/Desktop/airflow/airflow$ python3 <<'EOF'
   from airflow.dag_processing.bundles.manager import DagBundlesManager
   from airflow.utils.session import create_session
   
   manager = DagBundlesManager()
   with create_session() as session:
       manager.sync_bundles_to_db(session=session)
       print("sync_bundles_to_db() success")
   
   print("Bundles:", [b.name for b in manager.get_all_dag_bundles()])
   EOF
   2026-01-16T07:32:56.149137Z [info     ] setup plugin alembic.autogenerate.schemas [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:32:56.149383Z [info     ] setup plugin alembic.autogenerate.tables [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:32:56.149584Z [info     ] setup plugin alembic.autogenerate.types [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:32:56.149732Z [info     ] setup plugin alembic.autogenerate.constraints [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:32:56.149900Z [info     ] setup plugin alembic.autogenerate.defaults [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:32:56.150033Z [info     ] setup plugin alembic.autogenerate.comments [alembic.runtime.plugins] loc=plugins.py:37
   2026-01-16T07:32:56.228499Z [info     ] DAG bundles loaded: dags-folder, example_dags [airflow.dag_processing.bundles.manager.DagBundlesManager] loc=manager.py:179
   sync_bundles_to_db() success
   Bundles: ['dags-folder', 'example_dags']
   rickychen@airflow-dev:~/Desktop/airflow/airflow$ 
   ```


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700693841


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   Yes, you are right! This is the simplest and best approach.
   
   Thanks a lot, I learned a lot from this discussion. 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2696495330


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########


Review Comment:
   Done, removed the unused session parameter. 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2689947393


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########


Review Comment:
   (I missed this earlier)one small nit- just checking  -  Do we need to remove` session()` from here, since we are not using ? 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2689947393


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########


Review Comment:
   (I missed this earlier) just checking  -  Do we need to remove` session()` from here, since we are not using ? 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700532327


##########
.pre-commit-config.yaml:
##########


Review Comment:
   Done! Fixed the last remaining file (`scheduler_job_runner.py`) and simplified the pattern to `^airflow-core/.*\.py$|`. Thanks!



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3762959094

   ### Backport failed to create: v3-1-test. View the failure log <a href='https://github.com/apache/airflow/actions/runs/21092333958'> Run details </a>
   
   <table>
       <tr>
           <th>Status</th>
           <th>Branch</th>
           <th>Result</th>
       </tr>
       <tr>
           <td>❌</td>
           <td>v3-1-test</td>
           <td><a href="https://github.com/apache/airflow/commit/076f5199afa0acb2863e223362211135fecf739e"><img src='https://img.shields.io/badge/Commit-076f519-red' alt='Commit Link'></a></td>
       </tr>
   </table>
   
   You can attempt to backport this manually by running:
   
   ```bash
   cherry_picker 076f519 v3-1-test
   ```
   
   This should apply the commit to the v3-1-test branch and leave the commit in conflict state marking
   the files that need manual conflict resolution.
   
   After you have resolved the conflicts, you can continue the backport process by running:
   
   ```bash
   cherry_picker --continue
   ```
   


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3762963500

   Thanks everyone for the reviews and thoughtful discussions. Much appreciated!


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "jscheffl (via GitHub)" <gi...@apache.org>.
jscheffl commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3762977274

   No backport in my view.


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2671495566


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########


Review Comment:
   Changed .filter() to .where() for Select objects as per SQLA2 best practices.



-- 
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 airflow-core/src to use SQLA2 [airflow]

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


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -183,17 +184,17 @@ def readable_config(self):
 config_dict: dict[str, _TableConfig] = {x.orm_model.name: x for x in sorted(config_list)}
 
 
-def _check_for_rows(*, query: Query, print_rows: bool = False) -> int:
-    num_entities = query.count()
+def _check_for_rows(*, query: Select, print_rows: bool = False, session: Session) -> int:

Review Comment:
   Should query be renamed to statement 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


Re: [PR] Refactor airflow-core/src to use SQLA2 [airflow]

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


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700649049


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   I think `func.count()` is the right approach here since we need to count matching rows. The query above (`select(Log.dttm)`) fetches a datetime value, which has a different purpose. Using `func.count()` performs the counting in the database efficiently, whereas alternatives like `len(session.scalars(...).all())` would fetch all rows to Python first. 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700733370


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   Thanks for raising the question and for the review!



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3762614618

   OOPS Conflict !! 
   
   I believe the deprecated query part was removed from `airflow-core/src/airflow/utils/db_cleanup.py` by someone else and has already been merged


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "rickychen-infinirc (via GitHub)" <gi...@apache.org>.
rickychen-infinirc commented on PR #59918:
URL: https://github.com/apache/airflow/pull/59918#issuecomment-3708160261

   > Static checks are failing !! Could you please fix them ?
   
   Thanks for the review! You're partially right.
   I've removed the migrations line since I reverted those changes and this PR no longer modifies any migration files.
   However, the dag_processing and utils lines are intentional per the process described in #59402 - this PR modifies:
   
   airflow-core/src/airflow/dag_processing/bundles/manager.py
   airflow-core/src/airflow/utils/db_cleanup.py
   
   I've rebased to latest main and all pre-commit checks pass now.


-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "Prab-27 (via GitHub)" <gi...@apache.org>.
Prab-27 commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2668439741


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########


Review Comment:
   This works fine but I believe ` where()` is better since the `query` comes from the `Select` class . 
   related doc - [here](https://docs.sqlalchemy.org/en/14/core/selectable.html#sqlalchemy.sql.expression.Select.filter)
   
   What do you think ? 



-- 
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 airflow-core/src to use SQLA2 [airflow]

Posted by "ricky-chaoju (via GitHub)" <gi...@apache.org>.
ricky-chaoju commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2671503732


##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -332,10 +333,10 @@ def _build_query(
     dag_ids: list[str] | None = None,
     exclude_dag_ids: list[str] | None = None,
     **kwargs,
-) -> Query:
+) -> Select:
     base_table_alias = "base"
     base_table = aliased(orm_model, name=base_table_alias)
-    query = session.query(base_table).with_entities(text(f"{base_table_alias}.*"))
+    query = select(text(f"{base_table_alias}.*")).select_from(base_table)

Review Comment:
   OK! Renamed query to statement to better reflect that it's now a Select object rather than a Query object.



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