]> 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:10 +0000 (15:03 -0400)
commitdf5583de9c44ae785a61e75f626bfb16b615420e
tree04d9bebd4b3f817f0a6c986cb4ebb4d3a25aae72
parent5995834ee06fc5cae45f86992d778fd5357c08ee
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
doc/build/changelog/unreleased_20/13481.rst [new file with mode: 0644]
lib/sqlalchemy/sql/schema.py
test/sql/test_metadata.py