Skip to content

Fix log template sync failing when a custom SQL Alchemy schema is configured - #70793

Merged
vatsrahul1001 merged 5 commits into
apache:mainfrom
Aaryan123456679:fix/logtemplate-custom-schema-47300
Oct 20, 2026
Merged

vatsrahul1001 merged 5 commits into
apache:mainfrom
Aaryan123456679:fix/logtemplate-custom-schema-47300

Conversation

@Aaryan123456679

@Aaryan123456679 Aaryan123456679 commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

When sql_alchemy_schema is set, reflect_tables() derived the schema to reflect a mapped class's table by splitting its bare __tablename__ on a dot, which discards the schema entirely for classes like LogTemplate whose table name has no dot. synchronize_log_template() then looked up the reflected table by that same bare name, which also does not match how SQLAlchemy keys schema-qualified tables in the reflected metadata. Together these left the log_template table unrecognized under a custom schema, causing triggering a Dag to fail with a TypeError.

This derives the schema from the mapped class's own configured table instead of parsing its name, and looks the reflected table up by its schema-qualified key.

closes: #47300


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 5)
    Generated-by: Claude Code (Sonnet 5) following the guidelines

@eladkal eladkal added this to the Airflow 3.3.1 milestone Jul 31, 2026
@Aaryan123456679
Aaryan123456679 requested a review from eladkal July 31, 2026 17:43

@Dev-iL Dev-iL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Couple of suggestions.

Other than that, if AI was used in making this PR, please add a disclosure section to the PR description, per the accepted format.

Comment thread airflow-core/src/airflow/utils/db.py Resolved
Comment thread airflow-core/src/airflow/utils/db.py Resolved
…figured

When sql_alchemy_schema is set, reflect_tables() derived the schema to
reflect a mapped class's table under by splitting its bare __tablename__
on a dot, which discards the schema entirely for classes like
LogTemplate whose table name has no dot. synchronize_log_template()
then looked up the reflected table by that same bare name, which also
does not match how SQLAlchemy keys schema-qualified tables in the
reflected metadata. Together these left the log_template table
unrecognized under a custom schema, causing triggering a Dag to fail
with a TypeError.

Derive the schema from the mapped class's own configured table instead
of parsing its name, and look the reflected table up by its schema
-qualified key.
Not needed for this change per review feedback.
…chema

getattr(tbl, "__table__") worked around __table__ not being declared on
MappedClassProtocol, but SQLAlchemy's inspect() already exposes the same
table through a properly typed Mapper.local_table, so the getattr and its
explanatory comment are no longer needed.
@Aaryan123456679
Aaryan123456679 force-pushed the fix/logtemplate-custom-schema-47300 branch from 933619b to c866a23 Compare September 7, 2026 16:48

@subhramit subhramit 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.

Looks good

@vatsrahul1001 vatsrahul1001 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 fix looks correct to me. With no custom schema, local_table.schema is None and __table__.key equals __tablename__, so default deployments behave as before. String entries (all the db_cleanup.py callers) go through the unchanged branch, and LogTemplate is the only caller passing a mapped class.

A few optional comments:

  • Code comment: # Preserve the mapped class's own configured schema; see PR #70793. narrates the change and points at a PR number, so it can probably be dropped.
  • Simpler lookup: tbl.__table__.schema would avoid inspect(tbl, raiseerr=True).local_table.schema and match the LogTemplate.__table__.key call used in synchronize_log_template. As written, NoInspectionAvailable is a subclass of InvalidRequestError, so a bad class is silently skipped by the continue.
  • Same bug class elsewhere: check_team_names_can_be_lower_cased calls inspect(...).has_table(Team.__tablename__) with no schema=, so under a custom schema it would likely skip the check. Probably worth a follow-up issue rather than expanding this PR.

@vatsrahul1001 vatsrahul1001 added the backport-to-v3-4-test Backport to v3-4-test label Oct 18, 2026
@vatsrahul1001
vatsrahul1001 merged commit 6aee277 into apache:main Oct 20, 2026
79 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-4-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-4-test PR Link

github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Oct 20, 2026
…chema is configured (apache#70793)

* Fix log template sync failing when a custom SQL Alchemy schema is configured

When sql_alchemy_schema is set, reflect_tables() derived the schema to
reflect a mapped class's table under by splitting its bare __tablename__
on a dot, which discards the schema entirely for classes like
LogTemplate whose table name has no dot. synchronize_log_template()
then looked up the reflected table by that same bare name, which also
does not match how SQLAlchemy keys schema-qualified tables in the
reflected metadata. Together these left the log_template table
unrecognized under a custom schema, causing triggering a Dag to fail
with a TypeError.

Derive the schema from the mapped class's own configured table instead
of parsing its name, and look the reflected table up by its schema
-qualified key.

* Add newsfragment for log template custom schema fix

* Remove newsfragment for log template custom schema fix

Not needed for this change per review feedback.

* Use inspect().local_table instead of getattr for the mapped class's schema

getattr(tbl, "__table__") worked around __table__ not being declared on
MappedClassProtocol, but SQLAlchemy's inspect() already exposes the same
table through a properly typed Mapper.local_table, so the getattr and its
explanatory comment are no longer needed.
(cherry picked from commit 6aee277)

Co-authored-by: Aaryan Mahajan <aaryanmhjn@gmail.com>
aws-airflow-bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Oct 20, 2026
…chema is configured (apache#70793)

* Fix log template sync failing when a custom SQL Alchemy schema is configured

When sql_alchemy_schema is set, reflect_tables() derived the schema to
reflect a mapped class's table under by splitting its bare __tablename__
on a dot, which discards the schema entirely for classes like
LogTemplate whose table name has no dot. synchronize_log_template()
then looked up the reflected table by that same bare name, which also
does not match how SQLAlchemy keys schema-qualified tables in the
reflected metadata. Together these left the log_template table
unrecognized under a custom schema, causing triggering a Dag to fail
with a TypeError.

Derive the schema from the mapped class's own configured table instead
of parsing its name, and look the reflected table up by its schema
-qualified key.

* Add newsfragment for log template custom schema fix

* Remove newsfragment for log template custom schema fix

Not needed for this change per review feedback.

* Use inspect().local_table instead of getattr for the mapped class's schema

getattr(tbl, "__table__") worked around __table__ not being declared on
MappedClassProtocol, but SQLAlchemy's inspect() already exposes the same
table through a properly typed Mapper.local_table, so the getattr and its
explanatory comment are no longer needed.
(cherry picked from commit 6aee277)

Co-authored-by: Aaryan Mahajan <aaryanmhjn@gmail.com>
vatsrahul1001 added a commit that referenced this pull request Oct 20, 2026
…chema is configured (#70793) (#75194)

* Fix log template sync failing when a custom SQL Alchemy schema is configured

When sql_alchemy_schema is set, reflect_tables() derived the schema to
reflect a mapped class's table under by splitting its bare __tablename__
on a dot, which discards the schema entirely for classes like
LogTemplate whose table name has no dot. synchronize_log_template()
then looked up the reflected table by that same bare name, which also
does not match how SQLAlchemy keys schema-qualified tables in the
reflected metadata. Together these left the log_template table
unrecognized under a custom schema, causing triggering a Dag to fail
with a TypeError.

Derive the schema from the mapped class's own configured table instead
of parsing its name, and look the reflected table up by its schema
-qualified key.

* Add newsfragment for log template custom schema fix

* Remove newsfragment for log template custom schema fix

Not needed for this change per review feedback.

* Use inspect().local_table instead of getattr for the mapped class's schema

getattr(tbl, "__table__") worked around __table__ not being declared on
MappedClassProtocol, but SQLAlchemy's inspect() already exposes the same
table through a properly typed Mapper.local_table, so the getattr and its
explanatory comment are no longer needed.
(cherry picked from commit 6aee277)

Co-authored-by: Aaryan Mahajan <aaryanmhjn@gmail.com>
Co-authored-by: Rahul Vats <43964496+vatsrahul1001@users.noreply.github.com>
vatsrahul1001 added a commit that referenced this pull request Oct 20, 2026
…chema is configured (#70793) (#75194)

* Fix log template sync failing when a custom SQL Alchemy schema is configured

When sql_alchemy_schema is set, reflect_tables() derived the schema to
reflect a mapped class's table under by splitting its bare __tablename__
on a dot, which discards the schema entirely for classes like
LogTemplate whose table name has no dot. synchronize_log_template()
then looked up the reflected table by that same bare name, which also
does not match how SQLAlchemy keys schema-qualified tables in the
reflected metadata. Together these left the log_template table
unrecognized under a custom schema, causing triggering a Dag to fail
with a TypeError.

Derive the schema from the mapped class's own configured table instead
of parsing its name, and look the reflected table up by its schema
-qualified key.

* Add newsfragment for log template custom schema fix

* Remove newsfragment for log template custom schema fix

Not needed for this change per review feedback.

* Use inspect().local_table instead of getattr for the mapped class's schema

getattr(tbl, "__table__") worked around __table__ not being declared on
MappedClassProtocol, but SQLAlchemy's inspect() already exposes the same
table through a properly typed Mapper.local_table, so the getattr and its
explanatory comment are no longer needed.
(cherry picked from commit 6aee277)

Co-authored-by: Aaryan Mahajan <aaryanmhjn@gmail.com>
Co-authored-by: Rahul Vats <43964496+vatsrahul1001@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v3-4-test Backport to v3-4-test type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LogTemplate table not seeded in custom schema causes TypeError when triggering DAG

5 participants