Skip to content

Conversation

@champon1020
Copy link
Contributor

@champon1020 champon1020 commented Oct 5, 2023

Fix the the logic of checking dataflow job state in _check_dataflow_job_state method.

Closes: #34767

The expected_terminal_state parameter was introduced to Dataflow operators in #34217.
However, it raises the exception when wait_until_finished = True although the dataflow job state is JOB_STATE_DONE.
Then, I divides the logic of checking terminal state into the case that expected_terminal_state is JOB_STATE_RUNNING and others.


^ 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 newsfragments.

@boring-cyborg boring-cyborg bot added area:providers provider:google Google (including GCP) related issues labels Oct 5, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 5, 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.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    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

@champon1020 champon1020 marked this pull request as ready for review October 5, 2023 20:08
Comment on lines +423 to +425
if current_state == self._expected_terminal_state:
if self._expected_terminal_state == DataflowJobStatus.JOB_STATE_RUNNING:
return not self._wait_until_finished
Copy link
Member

Choose a reason for hiding this comment

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

I never used this operator, but I wonder what is _expected_terminal_state and why we may return False if _wait_until_finished is set the True and the state is equals to the provided expected terminal state 🤔

Copy link
Contributor Author

@champon1020 champon1020 Oct 5, 2023

Choose a reason for hiding this comment

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

_expected_terminal_state is optional parameter indicating which dataflow job state is considered as a success (discussed in #8553 (comment)).

I think the coexistence of two similar parameters, _wait_until_finished and _expected_terminal_state, causes this weird implementation (What _wait_until_finished is True has the same meaning as what _expected_terminal_state is DataflowJobStatus.JOB_STATE_DONE). So, it would be better to remove _wait_until_finished if we adopt _expected_terminal_state 🤔

Copy link
Contributor Author

@champon1020 champon1020 Oct 5, 2023

Choose a reason for hiding this comment

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

why we may return False if _wait_until_finished is set the True and the state is equals to the provided expected terminal state

Based on the above, this is because _wait_until_finished was applied preferentially compared to _expected_terminal_state in the original implementation.

Choose a reason for hiding this comment

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

any solution regarding this problem? I am facing the same problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asafeunico As the temporary solution, you can use the version 10.8.0 of apache-airflow-providers-google without this problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm the author of #34217 and sincerely apologize for the mess!
I ensured that the existing tests passed, but I didn't consider adding the JOB_STATE_DONE - which is problematic for that if case.
As @champon1020 stated, _wait_until_finished should have been applied preferentially compared to expected_terminal_state to avoid breaking default behavior.
I agree that having both params is somewhat confusing, and we should revise deprecating _wait_until_finished in the future.
The suggested solution LGTM, thank you for fixing it up!

Comment on lines +423 to +425
if current_state == self._expected_terminal_state:
if self._expected_terminal_state == DataflowJobStatus.JOB_STATE_RUNNING:
return not self._wait_until_finished
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm the author of #34217 and sincerely apologize for the mess!
I ensured that the existing tests passed, but I didn't consider adding the JOB_STATE_DONE - which is problematic for that if case.
As @champon1020 stated, _wait_until_finished should have been applied preferentially compared to expected_terminal_state to avoid breaking default behavior.
I agree that having both params is somewhat confusing, and we should revise deprecating _wait_until_finished in the future.
The suggested solution LGTM, thank you for fixing it up!

@shahar1
Copy link
Contributor

shahar1 commented Nov 10, 2023

@eladkal Could you please take a look? Thanks!

@eladkal eladkal merged commit 8fd5ac6 into apache:main Nov 10, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Nov 10, 2023

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) provider:google Google (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dataflow job is failed when wait_until_finished=True although the state is JOB_STATE_DONE

6 participants