Fix common.ai example DAGs failing to parse without the sql extra#68497
Conversation
|
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
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
67d1f55 to
be1ca49
Compare
kaxil
left a comment
There was a problem hiding this comment.
The intention of examples Dags is to show how something can be use and easy copy/paste-able and not to be able to run with all
Combination of optionals deps
There was a problem hiding this comment.
Hi @kaxil , thanks for the review. I understand you guys wanting to keep examples simple and copy-paste-able.
Just two things I wanted to flag though:
-
Two example Dags in the same provider already use this exact guard pattern (
example_langchain_toolset_bridge.pyandexample_pydantic_ai_hook.py) both dotry/exceptwith None fallback + if X is not None: guards. My PR just follows the same convention. If this pattern isn't the right approach, should those two be updated as well? I would be happy to undo their guards -
If the guards aren't the way to go, what would you suggest instead? Running uv sync (the documented dev setup) doesn't install the [sql] extra, so all 7 Dags show up as import errors out of the box. Maybe take a different approach like excluding them from parsing when the extra isn't installed, or adding the extra to the dev dependencies? whatever you think makes sense but it's just something that I noticed when setting up my environment that was a clear error and eye-sore to any developer working on this repository. cc @jroachgolf84
I don't see a
|
|
Looks like it was a recent merge: #66161 that loads example dags from all providers. We can probably do something better with the example dags by raising |
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
Fix common.ai example DAGs failing to parse without the
[sql]extraSeven example DAGs in
providers/common/aifail to parse whensqlglotis not installed (i.e. the optional[sql]extra is not present). The DAG processor marks them as import errors, even thoughsqlglotis intentionally an optional dependency.Problem
SQLToolsetandLLMSQLQueryOperatorraiseAirflowOptionalProviderFeatureExceptionat import time whensqlglotis missing. The example DAGs import these at the module level, which causes the entire DAG file to fail during parsing. The DAG processor catches this with a genericexcept BaseExceptionand marks the file as an import error — there is no special handling forAirflowOptionalProviderFeatureException.Running
uv sync(the documented setup) does not install the[sql]extra, so all seven DAGs error on a fresh dev environment.Fix
Wrap the optional imports in
try/except Exceptionwith aNonefallback, and guard the DAG definitions that use the optional class withif X is not None:. DAGs in the same file that don't use the optional dependency remain unguarded and always load.This matches the established pattern already used by two DAGs in the same provider (
example_langchain_toolset_bridge.pyandexample_pydantic_ai_hook.py), as well as other providers in the codebase (e.g.amazon/athena_sql.py,amazon/redshift_sql.py).Files changed
example_agent.pyexample_agent_capabilities.pyexample_agent_durable.pyexample_agent_skills.pyexample_llm_sql.pyexample_llm_survey_analysis.pyexample_llm_survey_agentic.pyBefore (7 DAG import errors)
After (0 DAG import errors)
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.