Skip to content
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

Automatically import move standard operators / hooks etc with deprecation from old location #43582

Open
1 task done
potiuk opened this issue Nov 1, 2024 · 2 comments
Open
1 task done
Labels
area:core kind:meta High-level information important to the community
Milestone

Comments

@potiuk
Copy link
Member

potiuk commented Nov 1, 2024

Body

For compatibility reason we wanted to "redirect" all the moved "airflow.operators" , "airflow.hooks" etc. to "standard" provider in Airflow 3 - with deprectation warning.

In the past we were doing it with our deprecation include but @ashb mentioned that he found another way. @gopidesupavan - that would be a follow up after #42081 and #42252 .

@ashb -> can you please explain the mechanism you found?

Committer

  • I acknowledge that I am a maintainer/committer of the Apache Airflow project.
@potiuk potiuk added the kind:meta High-level information important to the community label Nov 1, 2024
@potiuk potiuk added this to the Airflow 3.0.0 milestone Nov 1, 2024
@dosubot dosubot bot added the area:core label Nov 1, 2024
@gopidesupavan
Copy link
Member

Oh yeah that would helpful :).

When this discussion began a while ago, i heard from the discussion using meta path, then I experimented with using this to redirect old imports to new ones.

ash please suggest your approach.

import sys
import importlib

class ModuleRedirectSpec:
    def __init__(self, redirects):
        self.redirects = redirects

    def find_spec(self, old_module_ref, path, target=None):
        if old_module_ref in self.redirects:
            new_module_name = self.redirects[old_module_ref]
            return importlib.util.find_spec(new_module_name)
        return None

redirects = {
    "airflow.operators.bash": "airflow.providers.standard.operators.bash"
}
sys.meta_path.insert(0, ModuleRedirectSpec(redirects))

@potiuk
Copy link
Member Author

potiuk commented Nov 1, 2024

And let's not forget deprecations :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:core kind:meta High-level information important to the community
Projects
None yet
Development

No branches or pull requests

2 participants