Skip to content

Fix returned value when ShortCircuitOperator condition is falsy#32569

Merged
potiuk merged 2 commits into
apache:mainfrom
hussein-awala:fix/shortcircuit
Jul 15, 2023
Merged

Fix returned value when ShortCircuitOperator condition is falsy#32569
potiuk merged 2 commits into
apache:mainfrom
hussein-awala:fix/shortcircuit

Conversation

@hussein-awala

Copy link
Copy Markdown
Member

closes: #32553

Currently when we the python callable in the short circuit operator returns an non empty list or dict (truthy object), we return it without skipping the downstream tasks. And when it returns a falsy object like an empty dict, we evaluate it as a False and we skip the downstream tasks, but we return nothing, which is similar to return None.

This returned None raise an exception when we use the decorator with multiple_outputs=True, the only way to skip the downstream tasks is returning an empty dict, but the returned None brakes the post-processing method which push the returned Xcom. This PR returns the callable result as it is to fix this problem and to avoid any future problem.


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

@hussein-awala hussein-awala added this to the Airflow 2.6.4 milestone Jul 12, 2023
@hussein-awala hussein-awala added the type:bug-fix Changelog: Bug Fixes label Jul 12, 2023
tis = dr.get_task_instances()
assert tis[0].xcom_pull(task_ids=short_op_push_xcom.task_id, key="return_value") == "signature"
assert tis[0].xcom_pull(task_ids=short_op_no_push_xcom.task_id, key="return_value") is None
assert tis[0].xcom_pull(task_ids=short_op_no_push_xcom.task_id, key="return_value") is False

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is this considered a breaking change? If yes, how do you think we can handle it?

@uranusjr

Copy link
Copy Markdown
Member

I’m not saying this change is wrong, but maybe multiple_outputs=True should know how to handle None. Also this could use a better title since it appears in the version changelog.

@potiuk

potiuk commented Jul 15, 2023

Copy link
Copy Markdown
Member

I’m not saying this change is wrong, but maybe multiple_outputs=True should know how to handle None. Also this could use a better title since it appears in the version changelog.

Agree with the title, but maybe the "multiple-outputs"= None should be a separate thing- this one seems to to fix the problem with very small fix to make it more likely to get into maybe even 2.6.4

@potiuk potiuk changed the title Fix a bug in the ShortCircuitOperator Fix triggering when ShortCircuitOperator condition is Falsy Jul 15, 2023
@potiuk potiuk changed the title Fix triggering when ShortCircuitOperator condition is Falsy Fix returned value when ShortCircuitOperator condition is falsy Jul 15, 2023
@potiuk
potiuk merged commit 32a18d9 into apache:main Jul 15, 2023
@potiuk

potiuk commented Jul 15, 2023

Copy link
Copy Markdown
Member

Added issue for it #32622

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

Labels

type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ShortCircuitOperator returns None when condition is Falsy which errors with multiple_outputs=True

4 participants