]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commit
create placeholder tables for non-reflected remotes
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 29 Jan 2026 13:59:08 +0000 (08:59 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 29 Jan 2026 19:58:15 +0000 (14:58 -0500)
commita53d2f1a97ca14f0163adf53eb157bc6e2bf5db7
treebb6c84dafb62b2af594c61c9394ffbea002019f1
parent3faea256be67f9d7c5ccd4379c342922f489981b
create placeholder tables for non-reflected remotes

Fixed regression in version 1.18.0 due to :ticket:`1771` where autogenerate
would raise ``NoReferencedTableError`` when a foreign key constraint
referenced a table that was not part of the initial table load, including
tables filtered out by the
:paramref:`.EnvironmentContext.configure.include_name` callable or tables
in remote schemas that were not included in the initial reflection run.

The change in :ticket:`1771` was a performance optimization that eliminated
additional reflection queries for tables that were only referenced by
foreign keys but not explicitly included in the main reflection run.
However, this optimization inadvertently removed the creation of
:class:`.Table` objects for these referenced tables, causing autogenerate
to fail when processing foreign key constraints that pointed to them.

The fix creates placeholder :class:`.Table` objects for foreign key targets
that are not reflected, allowing the autogenerate comparison to proceed
without error while maintaining the performance improvement from
:ticket:`1771`. When multiple foreign keys reference different columns in
the same filtered table, the placeholder table accumulates all necessary
columns. These placeholder tables may be visible when using the
:paramref:`.EnvironmentContext.configure.include_object` callable to
inspect :class:`.ForeignKeyConstraint` objects; they will have the name,
schema and basic column information for the relevant columns present.

Fixes: #1787
Change-Id: I93ea9a41db1b20efb93c6cf657e63712c52f0580
alembic/autogenerate/compare/constraints.py
alembic/util/sqla_compat.py
docs/build/unreleased/1787.rst [new file with mode: 0644]
tests/test_autogen_diffs.py