Skip to content

Conversation

@NewSmoke38
Copy link

I modified the Drill provider to safely handle the absence of sqlalchemy by wrapping the import in a try-except block. It now raises AirflowOptionalProviderFeatureException in get_conn if the library is missing when actually needed.

Testing:
I verified this manually by running a script that simulates a missing sqlalchemy environment. This confirmed that while the parent DbApiHook typically relies on sqlalchemy, the Drill provider now loads successfully without it and only raises the correct exception when get_conn is called.

I look forward to your feedback.

closes: #59897

Handle ImportError and raise AirflowOptionalProviderFeatureException when a method needs sqlalchemy.
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 30, 2025

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Copy link
Collaborator

@sunank200 sunank200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also mark optional dependency for sqlalchemy in pyproject for drill

conn_md = self.get_connection(self.get_conn_id())

if create_engine is None:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


if create_engine is None:

raise AirflowOptionalProviderFeatureException("The 'sqlalchemy' library is required to use this hook.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise AirflowOptionalProviderFeatureException("The 'sqlalchemy' library is required to use this hook.")
raise AirflowOptionalProviderFeatureException(
"sqlalchemy is required for SQL filter clause generation. "
"Install it with: pip install 'apache-airflow-providers-drill[sqlalchemy]'"
)

@jscheffl
Copy link
Contributor

I am actually not sure whether we need this PR and check at-all. Drill-provider has dependency to sqlalchemy-drill>=1.1.0,!=1.1.6,!=1.1.7 defined and this indirectly has the requirement of sqlalchemy. So irrespective of core dependency it is alyways installing sqlalchemy, no conditional check needed in my view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add proper dependencies for sqlalchemy - drill

3 participants