]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Copy column defaults in Table.to_metadata
authorgoutamadwant <workwithgoutam@gmail.com>
Mon, 10 Aug 2026 13:27:21 +0000 (09:27 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 10 Aug 2026 19:03:53 +0000 (15:03 -0400)
commit9851e61e1229485ddec6010095bf696e392d7416
tree506cc874f5b7ed006328d9dafe5cb2295e23cd05
parenta46549de6abd77e55b5f5f250ab04aebe4b1f665
Copy column defaults in Table.to_metadata

``Table.to_metadata()`` reused the original column's ``default``,
``onupdate``, ``server_default``, and ``server_onupdate`` objects.
Attaching those objects to the copied column changed their ``column``
reference, leaving the original column's defaults associated with the
copy.

This change copies each default generator before constructing the new
column.  Sequence defaults are copied into the target metadata
collection so both the original and copied metadata retain their own
sequence objects.

Regression tests verify ownership for client-side defaults, server-side
defaults, on-update values, and sequence defaults.  Existing merge-copy
expectations now assert that each copied default remains associated with
its own column.

Fixes: #13481
Closes: #13482
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13482
Pull-request-sha: 3dfbe0d91c99cd33bb059937478b9ecb398d3613

Change-Id: Ifceb7802028ff8560937b265c2f55ed93e657fc5
(cherry picked from commit 17758bc8f6e8024e58177159941509eaa66bd074)
doc/build/changelog/unreleased_20/13481.rst [new file with mode: 0644]
lib/sqlalchemy/sql/schema.py
test/sql/test_metadata.py