huymq1710 commented on code in PR #30117:
URL: https://github.com/apache/airflow/pull/30117#discussion_r1140578889


##########
airflow/cli/commands/dag_command.py:
##########
@@ -292,40 +292,47 @@ def dag_next_execution(args):
     """
     dag = get_dag(args.subdir, args.dag_id)
 
-    if dag.get_is_paused():
-        print("[INFO] Please be reminded this DAG is PAUSED now.", 
file=sys.stderr)
-
     with create_session() as session:
-        max_date_subq = (
-            session.query(func.max(DagRun.execution_date).label("max_date"))
-            .filter(DagRun.dag_id == dag.dag_id)
-            .subquery()
-        )
-        max_date_run: DagRun | None = (
-            session.query(DagRun)
-            .filter(DagRun.dag_id == dag.dag_id, DagRun.execution_date == 
max_date_subq.c.max_date)
-            .one_or_none()
-        )
+        last_parsed_dag: DagModel = 
session.query(DagModel).filter(DagModel.dag_id == dag.dag_id).one()
+
+    if last_parsed_dag.get_is_paused():
+        print("[INFO] Please be reminded this DAG is PAUSED now.", 
file=sys.stderr)
+        print(last_parsed_dag.next_dagrun.isoformat())
+    else:
+        with create_session() as session:
+            max_date_subq = (
+                
session.query(func.max(DagRun.execution_date).label("max_date"))
+                .filter(DagRun.dag_id == dag.dag_id)
+                .subquery()
+            )
+            max_date_run: DagRun | None = (
+                session.query(DagRun)

Review Comment:
   Tested --> Should be outside of the with create_session() block. ✅ 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to