-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
[AIRFLOW-6006] Remove dag out of airflow package import. Depends on [AIRFLOW-6004] [AIRFLOW-6005] #6598
Closed
potiuk
wants to merge
4
commits into
apache:master
from
PolideaInternal:remove-dag-out-of-airflow-package-import
Closed
[AIRFLOW-6006] Remove dag out of airflow package import. Depends on [AIRFLOW-6004] [AIRFLOW-6005] #6598
potiuk
wants to merge
4
commits into
apache:master
from
PolideaInternal:remove-dag-out-of-airflow-package-import
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
potiuk
force-pushed
the
remove-dag-out-of-airflow-package-import
branch
7 times, most recently
from
November 18, 2019 03:27
c278c49
to
2d2ae55
Compare
This seems like it's changing module locations - should a note be added to |
@mattbowden-ookla -> yep. I plan to update the UPDATING.md once we get to agreement if this is a good approach in general and how to untangle some of the implicit dependencies we have - discussion in #6596. |
potiuk
force-pushed
the
remove-dag-out-of-airflow-package-import
branch
5 times, most recently
from
November 19, 2019 22:25
28590d8
to
4f02e45
Compare
There were a number of problems involving cyclic imports in Airflow's core. Mainly about settingsi, DAG context management, base operator imports and serialisation. Some of those problems were workarounded by #pylint: disables (for pylint), some of them were bypassed with TYPE_CHECKING (for mypy) and some of them were just hidden because pylint check was splitting filei lists while TravisiCI build. This commit fixes most of the problems (only executor problem is left) and removes all the workarounds. The fixes are: * Context for DAG context management was loaded from settings and Now context managemen is moved to DAG and 'import settings' is not needed in baseoperator, subdag_operator. * Serialized Fields are lazy initialised - they were previously initialized while parsing the python modules which made it impossible to avoid cycles. * SerializedDagModel is removed from 'airflow.models' and imported directly from serialization package. This is only internal class and does not need to be exposed via models * BaseOperator in core is imported from baseoperator package rather than from 'airflow.models'. This helps in importing the whole airflow __init__ of 'airflow' without having to pay attention to the sequence of imports there. * BaseOperator on the other hand is imported from 'airflowi.models' in operators/DAGs/hooks/sensors. This is important for Backporting (AIP-21) * The imports of BaseOperator are enforced with pre-commit. * All the pylint/mypy hacks related to cyclic imports are removed
There are cyclic imports detected seemingly randomly by pylint checks when some of the PRs are run in CI: ************* Module airflow.utils.log.json_formatter airflow/utils/log/json_formatter.py:1:0: R0401: Cyclic import (airflow.executors -> airflow.executors.kubernetes_executor -> airflow.kubernetes.pod_generator) (cyclic-import) airflow/utils/log/json_formatter.py:1:0: R0401: Cyclic import (airflow -> airflow.executors -> airflow.executors.kubernetes_executor -> airflow.kubernetes.pod_launcher) (cyclic-import) airflow/utils/log/json_formatter.py:1:0: R0401: Cyclic import (airflow.executors -> airflow.executors.kubernetes_executor -> airflow.kubernetes.worker_configuration -> airflow.kubernetes.pod_generator) (cyclic-import) The problem is that airflow's _init_ contains a few convenience imports (AirflowException, Executors etc.) but it also imports a number of packages (for example kubernetes_executor) that in turn import the airflow package objects - for example airflow.Executor. This leads to cyclic imports if you import first the executors before airflow. Similar problem happens with executor._init_.py containing class "Executors" imported by all executors but at the same time some of the executors (for example KubernetesExecutor) import the very same Executor class. It was not deterministic because pylint usually uses as many processors as many are available and it splits the list of .py files between the separate pylint processors - depending on how the split is done, pylint check might or might not detect it. The cycle is always detected when all files are used. This might happen in pylint checks in pre-commit because they split a number of files they process between the multiple threads you have at your machine and sometimes it might happen that the files are imported in different order. As a solution, the executors "list" should be moved to a separate module. Also the name of constants was changed to not to be confused with class names and Executors class was renamed to AvailableExecutors. Additionally require_serial is set in pre-commit configuration to make sure cycle detection is deterministic.
AirflowException should always be imported directly from 'airflow' package.
As explained in https://issues.apache.org/jira/browse/AIRFLOW-6003 having classes/packages in "airflow" might lead to cyclic imports and is genreally a bad practice. It makes more sense to import those packages from where they belong - i.e. sub-packages of airflow in core and from airflow package from integrations/outside DAGs where risk of cyclic imports is very small.
potiuk
force-pushed
the
remove-dag-out-of-airflow-package-import
branch
from
November 23, 2019 21:37
4f02e45
to
3b275a5
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note to reviewer: Please take a look at the last commit as this PR depends on other PRs.
s explained in https://issues.apache.org/jira/browse/AIRFLOW-6003
having classes/packages in "airflow" might lead to cyclic imports
and is genreally a bad practice. It makes more sense to import
those packages from where they belong - i.e. sub-packages of airflow.
Make sure you have checked all steps below.
Jira
Description
Tests
Commits
Documentation