Skip to content

Conversation

@boushphong
Copy link
Contributor

@boushphong boushphong commented Mar 15, 2023

closes: #22474

  • This commit is to fix the inconsistent returned value of airflow dags next-execution cli command when the dag is paused and catchup is False

In brief:

  • When the dag is unpaused, the cli command would get the next-execution run from the DagRun model. However, when the dag is paused, getting the next-execution run from the DagRun model would yield the next dag run time from the last executed dag run, which is incorrect as time passes.
  • To avoid this, we can get the next-execution run time from dag_model.next_dag_run (as in: dag.html L143) to make it more consistent with the UI.

Modification:

  • Use only the DagModel to get a dag next execution info. This way we could:
    • Handle the catchup=False case and when the Dag is paused.
    • Handle the case of next execution info is None when args.num_executions is specified. Previous code will throw an error as follow: None type has no attribute logical_date ...
    • Modify test case to handle all dag parsing scenarios.

This is my first PR, please let me know if there is anything I could do differently.

@boring-cyborg
Copy link

boring-cyborg bot commented Mar 15, 2023

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@boushphong boushphong requested a review from uranusjr March 17, 2023 11:06
@boushphong boushphong marked this pull request as draft March 17, 2023 18:25
@boushphong boushphong marked this pull request as ready for review March 18, 2023 20:03
@boushphong boushphong marked this pull request as draft March 19, 2023 05:41
Comment on lines 301 to 304
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think I prefer the previous range(1, num) way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the range(1, num) way would require handling and printing None in 2 different places. 1 before the loop and 1 more within the for loop itself. I just think the handling all those cases within the loop would be more elegant. But if you insist ... 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I feel handling in two places is actually easier than having to check for 0 every time. If you really hate code duplication, you can define a local function to reuse the logic. But checking for the index in the loop almost always makes things unnecessarily complex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, will do!

boushphong and others added 4 commits March 22, 2023 01:43
@boushphong boushphong requested review from huymq1710 and uranusjr and removed request for uranusjr March 22, 2023 07:47
@boushphong boushphong marked this pull request as ready for review March 22, 2023 07:59
@boushphong boushphong requested review from huymq1710 and uranusjr and removed request for huymq1710 and uranusjr March 22, 2023 07:59
@boushphong
Copy link
Contributor Author

@uranusjr Just updated the PR's description. This PR is ready for review 🙇

Copy link
Contributor

@huymq1710 huymq1710 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@potiuk potiuk merged commit c63836c into apache:main Mar 22, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Mar 22, 2023

Awesome work, congrats on your first merged pull request!

@eladkal eladkal added this to the Airflow 2.5.3 milestone Mar 22, 2023
@pierrejeambrun pierrejeambrun added the type:bug-fix Changelog: Bug Fixes label Mar 22, 2023
pierrejeambrun pushed a commit that referenced this pull request Mar 23, 2023
…command (#30117)

* Fix inconsistent returned value of `airflow dags next-execution` cli command

This commit is to fix the inconsistent returned value of `airflow dags next-execution` cli command when the dag is paused and catchup is False

---------

Co-authored-by: Bui Duc Phong[ Bui Duc Phong ] <bui.duc.phong@linecorp.com>
(cherry picked from commit c63836c)
pierrejeambrun pushed a commit that referenced this pull request Mar 24, 2023
…command (#30117)

* Fix inconsistent returned value of `airflow dags next-execution` cli command

This commit is to fix the inconsistent returned value of `airflow dags next-execution` cli command when the dag is paused and catchup is False

---------

Co-authored-by: Bui Duc Phong[ Bui Duc Phong ] <bui.duc.phong@linecorp.com>
(cherry picked from commit c63836c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLI type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI command "airflow dags next-execution" give unexpected results with paused DAG and catchup=False

6 participants