Skip to content

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

Open
Aaryan123456679 wants to merge 3 commits into
apache:mainfrom
Aaryan123456679:fix/logtemplate-custom-schema-47300
Open

Fix log template sync failing when a custom SQL Alchemy schema is configured#70793
Aaryan123456679 wants to merge 3 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

…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.
Comment thread airflow-core/newsfragments/70793.bugfix.rst Outdated
@eladkal eladkal added this to the Airflow 3.3.1 milestone Jul 31, 2026
@eladkal eladkal added type:bug-fix Changelog: Bug Fixes backport-to-v3-3-test Backport to v3-3-test labels Jul 31, 2026
Not needed for this change per review feedback.
@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.

# it dynamically, invisible to mypy's static checks here), so read it via
# ``getattr`` instead of a direct attribute access.
name = tbl.__tablename__
tbl_schema = getattr(tbl, "__table__").schema

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.

Consider using the local_table property available via SQLA's inspect api instead of getattr. I am not 100% sure about this, but prrhaps it could satisfy mypy, so type safety is retained.

if not sep:
tbl_schema, name = None, tbl
else:
# A mapped class already carries its configured schema (e.g. via

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.

I would trim the entire comment down to a few words or even remove it compeletely and let users refer to the PR for more context.

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

Labels

backport-to-v3-3-test Backport to v3-3-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

4 participants