Skip to content

Conversation

@drdenzy
Copy link
Contributor

@drdenzy drdenzy commented Nov 27, 2020

ease upgrade to Airflow 2.0

The NoAdditionalArgsInOperatorsRule class ensures that passing an
unrecognised arguments to operators causes an exception.

Passing unrecognised arguments is not allowed in Airflow 2.0

fixes #11042

Comment on lines +42 to +45
Copy link
Member

Choose a reason for hiding this comment

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

If this is here to suppress the log then it won't be necessary after #12657

Copy link
Member

Choose a reason for hiding this comment

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

@Dr-Denzy We can remove the logger.setLevel, and the outer try/finally now, as the PR mentioned here has been merged

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
msgs = rule.check(dags_folder=dag_file.name)
msgs = rule.check()

If we have this argument only for test then we should remove it and use mock similar to this:

class TestImportChangesRule:
@mock.patch("airflow.upgrade.rules.import_changes.list_py_file_paths")
@mock.patch(
"airflow.upgrade.rules.import_changes.ImportChangesRule.ALL_CHANGES",
[ImportChange.from_new_old_paths(NEW_PATH, OLD_PATH)],
)
def test_check(self, mock_list_files):
with NamedTemporaryFile("w+") as temp:
mock_list_files.return_value = [temp.name]
temp.write("from airflow.contrib import %s" % OLD_CLASS)
temp.flush()
msgs = ImportChangesRule().check()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, the Dependency Injection vs Mocking debate. :)

Copy link
Member

Choose a reason for hiding this comment

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

Having slept on it, I personally find the DI approach easier to understand than mocking.

Copy link
Member

Choose a reason for hiding this comment

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

@ashb personally I don't like features in code that are not used when running the code - it creates confusion when not commented

Copy link
Member

Choose a reason for hiding this comment

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

Also true.

Copy link
Member

Choose a reason for hiding this comment

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

@turbaszek Since you and I don't agree, and both approaches already exist in the code base, are you happy to let @Dr-Denzy decide on which approach to user?

Copy link
Member

Choose a reason for hiding this comment

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

@turbaszek Since you and I don't agree, and both approaches already exist in the code base, are you happy to let @Dr-Denzy decide on which approach to user?

Yes, no objection to keep it as it is - we already use this approach 👌

@turbaszek turbaszek added the area:upgrade Facilitating migration to a newer version of Airflow label Nov 27, 2020
@ashb ashb changed the title created NoAdditionalArgsInOperatorsRule class to Add upgrade check rule for unrecognized arguments to Operators Nov 27, 2020
@kaxil kaxil changed the base branch from v1-10-test to v1-10-stable November 27, 2020 21:44
@kaxil kaxil force-pushed the create-NoAdditionalArgsInOperatorsRule-to-ease-upgrade-airflow-2-0 branch from be64eff to 2e03ac1 Compare November 27, 2020 21:45
@drdenzy drdenzy force-pushed the create-NoAdditionalArgsInOperatorsRule-to-ease-upgrade-airflow-2-0 branch 2 times, most recently from 0989c5c to b62d0f4 Compare November 30, 2020 17:17
@github-actions
Copy link

The Workflow run is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Backport packages$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.

@drdenzy drdenzy force-pushed the create-NoAdditionalArgsInOperatorsRule-to-ease-upgrade-airflow-2-0 branch from b62d0f4 to 274b826 Compare December 1, 2020 13:01
@kaxil
Copy link
Member

kaxil commented Dec 1, 2020

Weird, passed for me locally too

@potiuk
Copy link
Member

potiuk commented Dec 1, 2020

Weird, passed for me locally too

As discussed here: https://apache-airflow.slack.com/archives/C0146STM600/p1606855518349800 - I belive this might side-effect from another test using the same "test" dag_id. We have a few of those and there are a number of tests that are likely leaving some remnants in the DB. My guess would be, this is the case and cleaning in setUp/tearDown might solve the issue.

@turbaszek
Copy link
Member

Weird, passed for me locally too

As discussed here: https://apache-airflow.slack.com/archives/C0146STM600/p1606855518349800 - I belive this might side-effect from another test using the same "test" dag_id. We have a few of those and there are a number of tests that are likely leaving some remnants in the DB. My guess would be, this is the case and cleaning in setUp/tearDown might solve the issue.

Sounds familiar. I usually prefer to use tests names as dag/task ids as this make sure that we are not affected by side effects. But cleanup would be also nice.

@kaxil kaxil force-pushed the create-NoAdditionalArgsInOperatorsRule-to-ease-upgrade-airflow-2-0 branch from db306c3 to f1e5ccf Compare December 9, 2020 15:56
drdenzy and others added 4 commits December 10, 2020 18:07
ease upgrade to Airflow 2.0

The NoAdditionalArgsInOperatorsRule class ensures that passing an
unrecognized arguments to operators causes an exception.

Passing unrecognized arguments is not allowed in Airflow 2.0
Implemented suggestions made during the PR reviews.
@kaxil kaxil force-pushed the create-NoAdditionalArgsInOperatorsRule-to-ease-upgrade-airflow-2-0 branch from 162a24f to b932e0d Compare December 10, 2020 18:07
@kaxil kaxil force-pushed the create-NoAdditionalArgsInOperatorsRule-to-ease-upgrade-airflow-2-0 branch from b932e0d to 6c4a81d Compare December 10, 2020 18:19
Copy link
Member

@kaxil kaxil Dec 10, 2020

Choose a reason for hiding this comment

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

This was needed as we suppress DeprecationWarning and PendingDeprecationWarning when running pytest on CI:

Starting the tests with those pytest arguments: --verbosity=0 --strict-markers --durations=100 --cov=airflow/ --cov-config=.coveragerc --cov-report=xml:/files/coverage.xml --color=yes --maxfail=50 --pythonwarnings=ignore::DeprecationWarning --pythonwarnings=ignore::PendingDeprecationWarning --junitxml=/files/test_result.xml --setup-timeout=20 --execution-timeout=60 --teardown-timeout=20 -rfEX --with-db-init tests

Lol took few hours for me & Dennis to figure why we were not able to replicate it when running it with breeze:

root@e6768532ef19:/opt/airflow# pytest tests/upgrade/rules/test_no_additional_args_operators.py

until we ran it with:

root@e6768532ef19:/opt/airflow# pytest tests/upgrade/rules/test_no_additional_args_operators.py --pythonwarnings=ignore::DeprecationWarning --pythonwarnings=ignore::PendingDeprecationWarning

😄

Copy link
Member

Choose a reason for hiding this comment

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

Good work you two!

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Dec 10, 2020
@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 master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@kaxil kaxil force-pushed the create-NoAdditionalArgsInOperatorsRule-to-ease-upgrade-airflow-2-0 branch from 6c4a81d to 6bd2ae8 Compare December 10, 2020 19:24
@kaxil kaxil merged commit ad34838 into apache:v1-10-stable Dec 10, 2020
@kaxil kaxil deleted the create-NoAdditionalArgsInOperatorsRule-to-ease-upgrade-airflow-2-0 branch December 10, 2020 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:upgrade Facilitating migration to a newer version of Airflow full tests needed We need to run full set of tests for this PR to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create NoAdditionalArgsInOperatorsRule to ease upgrade to Airflow 2.0

5 participants