Skip to content

Rewrite the common.sql connections guide and fix the dialect extra name - #73605

Merged
kaxil merged 2 commits into
apache:mainfrom
astronomer:common-sql-connections-docs
Sep 23, 2026
Merged

kaxil merged 2 commits into
apache:mainfrom
astronomer:common-sql-connections-docs

Conversation

@kaxil

@kaxil kaxil commented Sep 23, 2026

Copy link
Copy Markdown
Member

The common.sql connections page was two paragraphs that said to pass a connection ID and that other parameters "can be passed as key word args to the operators". Those arguments actually go through hook_params. The page also never said that common.sql has no connection type of its own, which is the first thing someone reading it needs to know.

The rewrite covers what the operators actually do, all taken from BaseSQLOperator and DbApiHook:

  • They reuse a database provider's connection, and the page links to that provider's connection docs.
  • The hook is resolved from the connection type, and the task fails unless it is a DbApiHook. airflow providers hooks shows what a type resolves to.
  • database and hook_params override settings per task. Connection extras are merged into hook_params, and hook_params wins on conflict.
  • A table lists the extras every DbApiHook reads (placeholder, dialect, sqlalchemy_scheme, the insert/replace statement formats and the escape settings) with their defaults. These matter most for ODBC and JDBC connections, where the database can't be inferred from the URI.

The dialects page had a real bug. It told users to set dialect_name in the connection extras, but DbApiHook.dialect_name reads the dialect key. Anyone who followed the docs got the default dialect with no error.


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {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.

The connections page said nothing beyond 'pass a connection ID' and told
users to pass hook arguments as operator kwargs, which does not work. It
now explains that common.sql reuses database provider connections, how
the hook is resolved, the database and hook_params overrides, and the
connection extras every DbApiHook reads.

The dialects page told users to set dialect_name in the extras, but the
hook reads dialect.

@dabla dabla left a comment

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.

The rewrite is accurate on everything I checked against the source: no connection type of its own, hook resolved from the connection type with the DbApiHook isinstance check and its error message, database overriding the schema (Postgres sets hook.database, everything else hook.schema, same effect), extras merged into hook_params with hook_params winning, SQLSensor and GenericTransfer parameter names, the placeholder whitelist and warning, the SQLite/Presto/Trino ? default, the three statement templates and both escape settings with their defaults, and the dialect_name → dialect key fix on the dialects page. The :doc: cross-references (supported-database-types, apache-airflow-providers-postgres:connections/postgres) resolve with the existing intersphinx mapping.

One accuracy issue remains, and it is the same kind the PR sets out to fix: the dialect extra is documented as the knob for ODBC and JDBC, but DbApiHook.dialect_name prefers the parsed URI and then sqlalchemy_scheme, and OdbcHook always produces a parseable URI (mssql+pyodbc by default). So dialect is ignored for ODBC connections and the ODBC example's "dialect": "mssql" does nothing. Suggested wording is in comment [1]; comment [2] covers the example and the MSSQL provider dependency for MERGE upserts. Both are doc-only changes to lines already in the diff.

This is a diff-based review; deeper cross-file checks were limited to the hook, operator, sensor, dialect and ODBC/JDBC hook sources named above.

Comment thread providers/common/sql/docs/connections.rst Outdated
Comment thread providers/common/sql/docs/connections.rst Outdated
DbApiHook takes the dialect from the parsed connection URI first, then
sqlalchemy_scheme, and only then the dialect extra. OdbcHook always builds
a parseable URI from sqlalchemy_scheme, so the dialect extra is never read
for ODBC connections.
@kaxil
kaxil merged commit 63d5d50 into apache:main Sep 23, 2026
62 checks passed
@kaxil
kaxil deleted the common-sql-connections-docs branch September 23, 2026 12:21
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