Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clearing ti.next_method and ti.next_kwargs on task finish. #19183

Conversation

ReadytoRocc
Copy link
Contributor

@boring-cyborg
Copy link

boring-cyborg bot commented Oct 23, 2021

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 (flake8, 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

@ReadytoRocc
Copy link
Contributor Author

  • Updated tests to be parameterized per @jedcunningham's suggestion.
  • Added session.merge(self) to failure case in _run_raw_task (if State.finished) where we now need to commit. This follows the other cases.

Comment on lines +495 to +527
def failure():
raise AirflowException

def skip():
raise AirflowSkipException

def success():
return None

def reschedule():
reschedule_date = timezone.utcnow()
raise AirflowRescheduleException(reschedule_date)

_retries = 0
_retry_delay = datetime.timedelta(seconds=0)

if state == State.FAILED:
_python_callable = failure
elif state == State.SKIPPED:
_python_callable = skip
elif state == State.SUCCESS:
_python_callable = success
elif state == State.UP_FOR_RESCHEDULE:
_python_callable = reschedule
elif state in [State.FAILED, State.UP_FOR_RETRY]:
_python_callable = failure
_retries = 1
_retry_delay = datetime.timedelta(seconds=2)

with dag_maker("test_deferred_method_clear"):
task = PythonOperator(
task_id="test_deferred_method_clear_task",
python_callable=_python_callable,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def failure():
raise AirflowException
def skip():
raise AirflowSkipException
def success():
return None
def reschedule():
reschedule_date = timezone.utcnow()
raise AirflowRescheduleException(reschedule_date)
_retries = 0
_retry_delay = datetime.timedelta(seconds=0)
if state == State.FAILED:
_python_callable = failure
elif state == State.SKIPPED:
_python_callable = skip
elif state == State.SUCCESS:
_python_callable = success
elif state == State.UP_FOR_RESCHEDULE:
_python_callable = reschedule
elif state in [State.FAILED, State.UP_FOR_RETRY]:
_python_callable = failure
_retries = 1
_retry_delay = datetime.timedelta(seconds=2)
with dag_maker("test_deferred_method_clear"):
task = PythonOperator(
task_id="test_deferred_method_clear_task",
python_callable=_python_callable,
def run(state):
if state == State.FAILED:
raise AirflowException
if state == State.SKIPPED:
raise AirflowSkipException
if state == State.UP_FOR_RESCHEDULE:
raise AirflowRescheduleException(timezone.utcnow())
return None # SUCCESS
_retries = 0
_retry_delay = datetime.timedelta(seconds=0)
if state in [State.FAILED, State.UP_FOR_RETRY]:
_retries = 1
_retry_delay = datetime.timedelta(seconds=2)
with dag_maker("test_deferred_method_clear"):
task = PythonOperator(
task_id="test_deferred_method_clear_task",
python_callable=run,
op_args=[state],

Do the retries and retry_delay differences actually matter?

Copy link
Member

Choose a reason for hiding this comment

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

@ReadytoRocc, I'm going to merge this for 2.2.1, but can you follow up with refactoring the test when you get the chance? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jedcunningham thanks for the the suggestions. Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do the retries and retry_delay differences actually matter?
@jedcunningham I believe it would only matter for the following cases:

  1. State.FAILED needs retries set to 0 so that task goes into a state of failed.
  2. State.UP_FOR_RETRY needs retries set to 1 so that task goes into a state of retry.

I believe we can set _retry_delay once, default _retries = 0, and then only set _retries = 1, if State.UP_FOR_RETRY.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jedcunningham - PR for refactored tests: #19194

@jedcunningham jedcunningham added this to the Airflow 2.2.1 milestone Oct 24, 2021
@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Oct 24, 2021
@github-actions
Copy link

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.

@jedcunningham jedcunningham reopened this Oct 24, 2021
@jedcunningham jedcunningham merged commit 8a0d6c2 into apache:main Oct 24, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 24, 2021

Awesome work, congrats on your first merged pull request!

@jedcunningham
Copy link
Member

@ReadytoRocc, congrats on your first commit 🎉🚀

jedcunningham pushed a commit that referenced this pull request Oct 24, 2021
jedcunningham pushed a commit to astronomer/airflow that referenced this pull request Oct 26, 2021
sharon2719 pushed a commit to sharon2719/airflow that referenced this pull request Oct 27, 2021
jedcunningham pushed a commit to astronomer/airflow that referenced this pull request Oct 27, 2021
@jedcunningham jedcunningham added the type:bug-fix Changelog: Bug Fixes label Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
full tests needed We need to run full set of tests for this PR to merge type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deferred TI's next_method is not cleared when Clearing a Successful Task
2 participants