-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Avoid circular import problems when instantiating AWS SM backend #25810
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
Avoid circular import problems when instantiating AWS SM backend #25810
Conversation
bd068a2 to
44399b7
Compare
| # Avoid circular import problems when instantiating the backend during configuration. | ||
| from airflow.models.connection import Connection |
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.
Personally I have no idea how to catch such an issue, rather than just manually run some simple command for all known SecretsBackends:
❯ export AIRFLOW__SECRETS__BACKEND=full.qualified.name.to.SB
❯ export AIRFLOW__SECRETS__BACKEND_KWARGS='{}'
❯ airflow versionThere 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.
There’s not really a good way to catch this, mainly due to airflow.models too eagerly imports everything. #24486 would be a good general solution to the problem in general.
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.
Yeah. We definitely import too much in some core packages.
And we should indeed add secrets manager tests. But I think #24486 is not the solution to this problem. It is a good approach but we have a problem with internal architecture, not with imports.
The real problem is not importing stuff, the problem is that we actually HAVE a circular dependency here and it's because our configuration approach is pretty badly intertwined with other parts of the system in this case we have:
- configuration can read values by delegating to secrets manager
- secrets manager uses configuration to configure itself
While I agree local imports and TYPE_CHECKING can provide some solution to the problem, they are very prone to trigger similar problems.
I think we should finally do something about it - I think ti's a bad approach that two internal components of systems are depending bi-directionally on each other :). The dependency between those should be one way - either conf is using secrets backend or secrets backend using conf. Basically we have secrets -> conf -> secret dependency chain which makes it very easy to turn it into circular import problem.
Probably the best solution is to split out the part that secret REALLY need from conf and make it an "internal conf" (and then conf -> secret -> "internal conf" will be the correct dependency chain that will not lead to accidental triggering of such cricular imports.
Fix circular import problems when instantiating AWS SecretsManagerBackend in
apache-airflow-providers-amazon==5.0.0before
after
❯ export AIRFLOW__SECRETS__BACKEND=airflow.providers.amazon.aws.secrets.secrets_manager.SecretsManagerBackend ❯ airflow version 2.4.0.dev0cc: @o-nikolas @ferruzzi @vincbeck @potiuk