Skip to content

Conversation

@potiuk
Copy link
Member

@potiuk potiuk commented Nov 17, 2019

NOTE FOR REVIEWER: This change depends on #6596 #6702 #6696 so please review only the last commit.

For the sake of consistency, all the common components exposed directly
in 'airflow' init.py should be imported from there rather than
from sub-packages. This is important also for back-porting
purposes (AIP-21) to make sure that we are using stable imports.

This change does it and implements pre-commit that prevents importing
those common imports differently.

Make sure you have checked all steps below.

Jira

Description

  • Here are some details about my PR, including screenshots of any UI changes:

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:

Commits

  • My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain docstrings that explain what it does
    • If you implement backwards incompatible changes, please leave a note in the Updating.md so we can assign it to a appropriate release

@potiuk potiuk requested review from Fokko, KevinYang21, ashb, feluelle and mik-laj and removed request for KevinYang21 and mik-laj November 17, 2019 19:05
@potiuk potiuk force-pushed the remove-airflow-airflow-exception-imports branch 9 times, most recently from 3a43e29 to f61f006 Compare November 18, 2019 08:45
@potiuk
Copy link
Member Author

potiuk commented Nov 18, 2019

I think I nicely solved the problem of old imports. I figured out a nice way how to throw a deprecation warning in case someone import "from airflow impot AirflowException". It will still work, but during tests/execution it will log a deprecation warning and also you will see this deprecation warning in IDE:

Screenshot 2019-11-18 at 02 38 00

This is a I think a very straightforward way to avoid potential cyclic imports like the ones described in #6596 and opens up the possibility of removing the class from 'airflow' package in the future.

I have one problem though @mik-laj maybe you can help solving it. I added a new "deprecations" package where i will put all the "deprecated" classes. I had to remove it in autoapi_ignore because otherwise there were two candidates for AirflowException class in autoapi generation. Now I have another warning - when I generate doc I have the "missing module" error:

[AutoAPI] Mapping Data
WARNING: Cannot resolve import of unknown module airflow.deprecations in airflow
[AutoAPI] Rendering Data

I tried to add airflow.deprecations to 'autodoc_mock_imports' but it did not help. Can you please help with solving this?

@potiuk potiuk force-pushed the remove-airflow-airflow-exception-imports branch from f61f006 to 0fa20ac Compare November 18, 2019 09:43
@potiuk
Copy link
Member Author

potiuk commented Nov 18, 2019

I think I found a nice (though a but hackish :) ) way of making the docs build @mik-laj and others. See the change :).

@ashb
Copy link
Member

ashb commented Nov 18, 2019

Oh, I think I see the issue with both of my comments:

Because airflow/__init__.py unconditionally imports from airflow.deprecations import AirflowException it would always run.

Could we use https://docs.python.org/3/library/importlib.html#importlib.util.LazyLoader (new in v3.5) instead? That doesn't seem to work for an pip install -e environment so no. https://pypi.org/project/lazy-import/ might be an option though. Oh, this module is GPLv3 so won't work.

And as for the "two candidates for AirflowException class in autoapi generation": putting __all__ = ['AirflowException'] in the airflow/deprecations/airflow_exception_deprecated.py might help with that.

@potiuk
Copy link
Member Author

potiuk commented Nov 18, 2019

@ashb - I will try those approaches. First I have to fix the #6596 which is the base for that one and then will try some experimenting.

@potiuk potiuk force-pushed the remove-airflow-airflow-exception-imports branch 3 times, most recently from 4ae7bce to 70fd500 Compare November 19, 2019 00:38
@potiuk
Copy link
Member Author

potiuk commented Nov 19, 2019

@ashb - I looked at the options and now I implemented quickly version that does not do deprecation, but pre-commits. It requires:

  • 'from airflow import AirflowException' in "providers" and "contrib"
  • 'from airflow.exceptions import AirflowException' elsewhere

I think that might make perfect sense rather than deprecating. It's even more "constraining" for core developers. The check is pretty much self-explanatory:

[potiuk:/code/airflow] remove-airflow-airflow-exception-imports+ 3d11h32m58s ± pre-commit run airflow-exception --all-files
Make sure AirflowException is imported from airflow.exceptions in core.......................Passed
Make sure AirflowException is imported from airflow outside of core..........................Passed
[potiuk:/code/airflow] remove-airflow-airflow-exception-imports+ 3d11h33m25s ± pre-commit run airflow-settings --all-files
Make sure settings are imported individually as local imports.......................Passed

@potiuk potiuk force-pushed the remove-airflow-airflow-exception-imports branch 2 times, most recently from 9458142 to 971e0e3 Compare November 19, 2019 01:27
@potiuk potiuk changed the title [AIRFLOW-6005] Standardise common imports. Depends on [AIRFLOW-6004] [AIRFLOW-6010] [AIRFLOW-6005] SCommon classes should always be imported from airflow, Depends on [AIRFLOW-6004] [AIRFLOW-6010] Dec 1, 2019
@potiuk potiuk changed the title [AIRFLOW-6005] SCommon classes should always be imported from airflow, Depends on [AIRFLOW-6004] [AIRFLOW-6010] [AIRFLOW-6005] Common classes should always be imported from airflow, Depends on [AIRFLOW-6004] [AIRFLOW-6010] Dec 1, 2019
@potiuk potiuk force-pushed the remove-airflow-airflow-exception-imports branch from 1ed8492 to 43c5310 Compare December 1, 2019 19:06
@potiuk potiuk changed the title [AIRFLOW-6005] Common classes should always be imported from airflow, Depends on [AIRFLOW-6004] [AIRFLOW-6010] [AIRFLOW-6005] Common classes should always be imported from airflow, Depends on [AIRFLOW-6004] [AIRFLOW-6140] [AIRFLOW-6128] Dec 1, 2019
@potiuk
Copy link
Member Author

potiuk commented Dec 1, 2019

@ashb @mik-laj @feluelle -> That's the next one resulting from the untangling cyclic deps. This one should be helpful in keeping consistent import for common classes inside airflow codebase.

@potiuk potiuk force-pushed the remove-airflow-airflow-exception-imports branch 7 times, most recently from 3ffb65c to f14d7ab Compare December 2, 2019 09:04
@codecov-io
Copy link

codecov-io commented Dec 2, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@da088b3). Click here to learn what that means.
The diff coverage is 87.57%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #6597   +/-   ##
=========================================
  Coverage          ?   83.79%           
=========================================
  Files             ?      669           
  Lines             ?    37668           
  Branches          ?        0           
=========================================
  Hits              ?    31565           
  Misses            ?     6103           
  Partials          ?        0
Impacted Files Coverage Δ
airflow/utils/sqlalchemy.py 91.52% <ø> (ø)
airflow/operators/mssql_to_hive.py 100% <ø> (ø)
airflow/contrib/auth/backends/ldap_auth.py 0% <0%> (ø)
...ow/contrib/auth/backends/github_enterprise_auth.py 0% <0%> (ø)
airflow/contrib/auth/backends/kerberos_auth.py 0% <0%> (ø)
airflow/utils/log/gcs_task_handler.py 0% <0%> (ø)
airflow/contrib/auth/backends/google_auth.py 0% <0%> (ø)
...rflow/config_templates/default_webserver_config.py 0% <0%> (ø)
airflow/contrib/auth/backends/password_auth.py 0% <0%> (ø)
airflow/jobs/base_job.py 88.57% <100%> (ø)
... and 179 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da088b3...3d1182a. Read the comment docs.

@potiuk potiuk force-pushed the remove-airflow-airflow-exception-imports branch from f14d7ab to 8185939 Compare December 2, 2019 22:03
While adding type annotations, it was apparent that the code for
plugin manager and webserver initialisation was rather convoluted
and complex. This change fixes it as follow up after untangling
cyclic dependnencies.

As a side effect - it turned out that the test plugin view
in airflow RBAC implementation was not working since 1.10.1 - it threw "render
is not an attribute" error - this has been fixed in this commit
as well. The Plugins/TestView now works as expected. See
https://stackoverflow.com/questions/53701030/airflow-plugins-rbac-enabled-blueprint-not-working?answertab=active#tab-top
@potiuk potiuk changed the title [AIRFLOW-6005] Common classes should always be imported from airflow, Depends on [AIRFLOW-6004] [AIRFLOW-6140] [AIRFLOW-6128] [AIRFLOW-6005] Common classes should always be imported from airflow, Depends on [AIRFLOW-6128] Dec 9, 2019
For the sake of consistency, all the common components exposed directly
in 'airflow' __init__.py should be imported from there rather than
from sub-packages. This is important also for back-porting
purposes (AIP-21) to make sure that we are using stable imports.

This change does it and implements pre-commit that prevents importing
those common imports differently.
@potiuk potiuk force-pushed the remove-airflow-airflow-exception-imports branch from 8185939 to 3d1182a Compare December 9, 2019 12:08
@stale
Copy link

stale bot commented Jan 24, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jan 24, 2020
@stale stale bot closed this Jan 31, 2020
@potiuk potiuk reopened this Jan 31, 2020
@boring-cyborg boring-cyborg bot added area:dev-tools provider:amazon AWS/Amazon - related issues provider:microsoft-azure Azure-related issues labels Jan 31, 2020
@stale stale bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Jan 31, 2020
- id: common-imports
language: pygrep
name: Make sure AirflowConfigException is imported consistently 'from airflow'
entry: "from airflow\\.exception import.* AirflowConfigException"
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
entry: "from airflow\\.exception import.* AirflowConfigException"
entry: "from airflow\\.exceptions import.* AirflowConfigException"

Copy link
Member Author

Choose a reason for hiding this comment

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

Will come back to it some day :).

@potiuk
Copy link
Member Author

potiuk commented Feb 17, 2020

Since we are going to get rid of the airflow.init.py most likely - this one can be closed.

@potiuk potiuk closed this Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLI area:dev-tools provider:amazon AWS/Amazon - related issues provider:microsoft-azure Azure-related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants