-
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-6010] Remove cyclic imports and pylint disables #6601
[AIRFLOW-6010] Remove cyclic imports and pylint disables #6601
Conversation
3fffb90
to
a7136fc
Compare
c21d9d5
to
bec08d0
Compare
bec08d0
to
98addaf
Compare
@ashb @feluelle - but also @kaxil and @coufon as a lot of cyclic import problems were caused by DAG serialization, so please take a close look - maybe I overlooked something. I indeed went back to the drawing board and I think I fixed the problems with cyclic imports in simple, and elegant way. I yet have to fix migration for serialization table and run the tests, but I have all the reasons to believe, that the changes I made (mainly in imports but also few other places) are good and they will lead to much nicer and easier-to-reason-about code. Here is the detailed description of the changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much happier with the scope of this change, and the rules you've got in the contributing doc sound good to me
Oh we should probably put a note in UPDATING about the removal of |
98addaf
to
38594eb
Compare
@ashb - I renamaed it to "serialization_base.py -> SerializationBase class. |
Updated |
a08a27c
to
bee8cdb
Compare
@ashb @kaxil @feluelle @coufon -> waiting for Travis CI now. Since I was modifying BaseOperator I also updated/fixed a few typehints to 3.6, fixed few - previously pylint-disabled - warnings, and also extracted (PyCharm noticed it) the object_to_json as common code between SerializedDAG and SerializedBaseOperator. Nice code! though I hope in the future we will keep the non-cyclic imports and won't have to do unnecessary pylint: disables for them (and the TYPE_CHECKING hack was particularly "interesting" ;). I will add a shortly the Executors separation (and enable Pylint in 'require serial' mode) which means that it will be always processing all files (not in pylint_todo.txt) in single process and in case of more cycles they should be detected immediately + add some more 'best-practices' checks in pre-commit to guide the developers in the future so that they will not introduce cycles accidentally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good overall 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small comments, otherwise looking great @potiuk!
0e6b5c4
to
75d39a9
Compare
All checks passed @kaxil :) |
@potiuk - We have merge conflicts ! |
75d39a9
to
7018e68
Compare
@kaxil -> thanks! Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Unfortunately there are k8s errors 🙈
|
I restarted them - they were looking flaky. |
aaaaah.. another conflict, right after it passed :) |
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
7018e68
to
0e8be9e
Compare
rebased again |
Thanks @potiuk |
Finally :). Thanks @kaxil |
Jira
Description
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.
Tests
Commits
Documentation