Skip to content

Make OpenLineage SQL schema lookup configurable - #74776

Open
prabhnoor0212 wants to merge 1 commit into
apache:mainfrom
prabhnoor0212:make-openlineage-sql-schema-lookup-configurable
Open

prabhnoor0212 wants to merge 1 commit into
apache:mainfrom
prabhnoor0212:make-openlineage-sql-schema-lookup-configurable

Conversation

@prabhnoor0212

Copy link
Copy Markdown

Allow SQL OpenLineage extraction to skip external database schema lookups when they are slow or unreliable. When disabled, the SQLAlchemy engine is not created, while connection details remain available for database namespace and dialect identification.

This preserves table-level lineage parsing while allowing schema facets to be less complete.

Validation completed:

  • OpenLineage suite: 1,049 passed, 91 skipped
  • Common SQL suite: 571 passed, 14 skipped
  • Focused regression test and Ruff checks passed
  • prek run --from-ref main --stage pre-commit passed with Python 3.11
  • git diff --check passed

Was generative AI tooling used to co-author this PR?
  • Yes (OpenAI ChatGPT)

Generated-by: OpenAI ChatGPT following the guidelines at https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions


Allow deployments to avoid external database metadata lookups during SQL lineage extraction when those lookups are slow or unreliable.
@boring-cyborg

boring-cyborg Bot commented Oct 15, 2026

Copy link
Copy Markdown

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
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

return True
from airflow.providers.openlineage import conf

return conf.sql_use_external_connection()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changing should_use_external_connection() does not cover all SQL lineage extraction paths. For example, MySQLToGCSOperator calls get_openlineage_facets_with_sql() through common.compat. With a current OpenLineage provider, that resolves to the implementation in openlineage/sqlparser.py, which defaults to use_connection=True and never checks should_use_external_connection().

The check in common.compat only runs in its fallback implementation for older OpenLineage versions. Consequently, MySQLToGCSOperator can still query information_schema when sql_use_external_connection=False.

Please make the shared helper in openlineage/sqlparser.py honor the setting too, while preserving use_connection=False when explicitly passed by a caller.

@@ -321,7 +321,7 @@ def get_openlineage_facets_on_start(self) -> OperatorLineage | None:
hook=hook,
database_info=database_info,
database=self.database,
sqlalchemy_engine=hook.get_sqlalchemy_engine(),
sqlalchemy_engine=hook.get_sqlalchemy_engine() if use_external_connection else None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When the setting is false and the operator uses PostgresHook or MsSqlHook, extraction still calls get_openlineage_default_schema() before reaching this guard. Those implementations execute SELECT CURRENT_SCHEMA; and SELECT SCHEMA_NAME();, respectively, opening an external database connection. A slow or unavailable database can therefore still block extraction or raise before table-only lineage is generated. The disabled path also needs to avoid database-backed default-schema discovery or provide an offline fallback.

This branch has not been deployed

No deployments
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.

2 participants