]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
backport 6f02d5edd88fe247 to 1.4
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Apr 2022 20:19:16 +0000 (16:19 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Apr 2022 20:40:42 +0000 (16:40 -0400)
commite32937fa6a7dcc3d5087aa1f41049373ab9e4038
tree3ebe0286f2e956f2d9c0b49ecb60aaeecc53901b
parentba68a53fcb120f2dd7c56d7d71223452f9ea0113
backport 6f02d5edd88fe247 to 1.4

in 6f02d5edd88fe2475629438b0730181a2b00c5fe some cleanup
to ForeignKey repaired the use case of ForeignKey objects
referring to table name alone, by adding more robust
column resolution logic.  This change also fixes an issue
where the "referred column" naming convention key uses the
resolved referred column earlier than usual when a
ForeignKey is setting up its constraint.

Fixed bug where :class:`.ForeignKeyConstraint` naming conventions using the
``referred_column_0`` naming convention key would not work if the foreign
key constraint were set up as a :class:`.ForeignKey` object rather than an
explicit :class:`.ForeignKeyConstraint` object. As this change makes use of
a backport of some fixes from version 2.0, an additional little-known
feature that has likely been broken for many years is also fixed which is
that a :class:`.ForeignKey` object may refer to a referred table by name of
the table alone without using a column name, if the name of the referent
column is the same as that of the referred column.

The ``referred_column_0`` naming convention key was not previously not
tested with the :class:`.ForeignKey` object, only
:class:`.ForeignKeyConstraint`, and this bug reveals that the feature has
never worked correctly unless :class:`.ForeignKeyConstraint` is used for
all FK constraints. This bug traces back to the original introduction of
the feature introduced for :ticket:`3989`.

Fixes: #7958
Change-Id: I230d43e9deba5dff889b9e7fee6cd4d3aa2496d3
doc/build/changelog/unreleased_14/7958.rst [new file with mode: 0644]
lib/sqlalchemy/sql/schema.py
test/sql/test_metadata.py