Repository navigation
Fix log template sync failing when a custom SQL Alchemy schema is configured - #70793
vatsrahul1001 merged 5 commits into
Conversation
Dev-iL
left a comment
There was a problem hiding this comment.
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.
…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.
933619b to
c866a23
Compare
vatsrahul1001
left a comment
There was a problem hiding this comment.
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__.schemawould avoidinspect(tbl, raiseerr=True).local_table.schemaand match theLogTemplate.__table__.keycall used insynchronize_log_template. As written,NoInspectionAvailableis a subclass ofInvalidRequestError, so a bad class is silently skipped by thecontinue. - Same bug class elsewhere:
check_team_names_can_be_lower_casedcallsinspect(...).has_table(Team.__tablename__)with noschema=, so under a custom schema it would likely skip the check. Probably worth a follow-up issue rather than expanding this PR.
Backport successfully created: v3-4-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
…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>
…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>
…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>
…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>
When
sql_alchemy_schemais 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 likeLogTemplatewhose 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 thelog_templatetable unrecognized under a custom schema, causing triggering a Dag to fail with aTypeError.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?
Generated-by: Claude Code (Sonnet 5) following the guidelines