Codingaditya17 opened a new pull request, #67519: URL: https://github.com/apache/airflow/pull/67519
## Why This is a focused provider-specific PR for the broader provider lazy-loading effort discussed in the issue. The Elasticsearch provider currently imports the Elasticsearch Python client at module import time in `hooks/elasticsearch.py`. That means importing the provider hook also imports the external `elasticsearch` client package immediately, even when a DAG only needs to parse the hook module and does not actually create an Elasticsearch client. This PR makes that import lazy so the Elasticsearch client package is imported only when a connection/client is actually created. ## What changed Removed the module-level `from elasticsearch import Elasticsearch` import from the Elasticsearch hook module, added a type-only import under `TYPE_CHECKING`, and moved the runtime import into the places where the client is actually created: `ESConnection.__init__` and `ElasticsearchPythonHook._get_elastic_connection`. Also updated the affected unit test mock to patch `elasticsearch.Elasticsearch` directly now that the provider module no longer exposes `Elasticsearch` as a module-level import. ## Scope This PR only targets the Elasticsearch provider to keep the change small and reviewable. If this direction looks good, similar provider-specific lazy-loading PRs can be opened separately for other providers. ## Tests Ran `uv run pytest providers/elasticsearch/tests/unit/elasticsearch/hooks/test_elasticsearch.py -q` and got `26 passed, 1 warning`. Ran `uv run pytest providers/elasticsearch/tests/unit/elasticsearch -q` and got `131 passed, 1 warning`. Ran `uv run prek run --files providers/elasticsearch/src/airflow/providers/elasticsearch/hooks/elasticsearch.py providers/elasticsearch/tests/unit/elasticsearch/hooks/test_elasticsearch.py` and all checks passed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
