Fix circular imports when airflow starts#29494
Conversation
|
I have not found yet which change triggered it (for sure that was not the change by @o-nikolas #29257 as I reverted it and it did not help) but it seems our main cli Example stack trace I got before that one in various stages of the fix: Then: Then: |
3f82d72 to
9b9b930
Compare
9b9b930 to
5fe3d7b
Compare
When airflow CLI is started without generated config file the CLI fails with circular imports. Some of the util classes imported during such start were importing "constants" (in fact variables) from the setttings and this happened before settings were fully initialized. This PR moves all relevant top-level imports to be local imports and moves initialization of the State class with settings-defined colors to initialization() method in order to avoid those circular imports.
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
9de9c76 to
ffebd00
Compare
@potiuk I believe that a similar fix I applied in So importing from __future__ import annotations
import os
import argcomplete
-from airflow.cli import cli_parser
from airflow.configuration import conf
+from airflow.cli import cli_parser
def main():
"""Main executable function."""
if conf.get("core", "security") == "kerberos":
os.environ["KRB5CCNAME"] = conf.get("kerberos", "ccache") |
|
Well. It was failing after the fix from you. I checked it was there. I even reverted it to see if it changes anything. It did not. Maybe you can try to revert my fix and see if you can reproduce it. But now when I am thinking if it - maybe this was somehow connected to installed entrypoint and 'pip install -e .' caused some weird interaction? Because this is how I got it failing:
Maybe that was somehow my environmental problem ? Maybe you can double check it by reverting :) ? |
|
Ah yeah i see you proposed a new one - now (sorry on mobile). Yeah worth trying. I just know from the past that i had some nice ideas for fixing those problems and they often broke down when I tested them :) after some big changes. I would love to get those problems not reappear. |
|
Some time ago I tried to write specific tests for known and repeatable problem with circular imports. There is couple issues (I guess all could be solved):
|
|
I created a new PR which fixes We need this fix at each possible "entrypoint" into airflow runtime. It should only be these two places (unless others know of any more?) |
This would be so awesome to have. If you see the PR I linked (and the other one like it for |
* Fix circular imports when airflow starts from scratch When airflow CLI is started without generated config file the CLI fails with circular imports. Some of the util classes imported during such start were importing "constants" (in fact variables) from the setttings and this happened before settings were fully initialized. This PR moves all relevant top-level imports to be local imports and moves initialization of the State class with settings-defined colors to initialization() method in order to avoid those circular imports. * Update airflow/models/xcom.py Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com> --------- Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com> (cherry picked from commit 47b67f1)
* Fix circular imports when airflow starts from scratch When airflow CLI is started without generated config file the CLI fails with circular imports. Some of the util classes imported during such start were importing "constants" (in fact variables) from the setttings and this happened before settings were fully initialized. This PR moves all relevant top-level imports to be local imports and moves initialization of the State class with settings-defined colors to initialization() method in order to avoid those circular imports. * Update airflow/models/xcom.py Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com> --------- Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com> (cherry picked from commit 47b67f1)
When airflow CLI is started without generated config file the CLI fails with circular imports. Some of the util classes imported during such start were importing "constants" (in fact variables) from the setttings and this happened before settings were fully initialized.
This PR moves all relevant top-level imports to be local imports and moves initialization of the State class with settings-defined colors to initialization() method in order to avoid those circular imports.
^ 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.rstor{issue_number}.significant.rst, in newsfragments.