From: WiktorB2004 Date: Wed, 20 May 2026 20:05:41 +0000 (-0400) Subject: Fix ExcludeConstraint not forwarding info to parent constructor X-Git-Tag: rel_2_0_50~2^2 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=e5b38d6826f4dca933c295b55cc59b5137d9796e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix ExcludeConstraint not forwarding info to parent constructor Fixed issue where the :class:`.ExcludeConstraint` construct did not correctly forward the :paramref:`.ExcludeConstraint.info` parameter to the superclass, causing user-defined metadata to be lost. Pull request courtesy Wiktor Byrka. Fixes: #13317 Closes: #13316 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13316 Pull-request-sha: be7f4fee2c40d1986519e93145471faad61021af Change-Id: Idc4846f02127d1d39a8c638cb03b0379932e9fd6 (cherry picked from commit cf2984c31d1f3edcfd26801a8ac560d95b52892e) --- diff --git a/doc/build/changelog/unreleased_20/13317.rst b/doc/build/changelog/unreleased_20/13317.rst new file mode 100644 index 0000000000..8000af1f8b --- /dev/null +++ b/doc/build/changelog/unreleased_20/13317.rst @@ -0,0 +1,9 @@ +.. change:: + :tags: bug, postgresql + :tickets: 13317 + + Fixed issue where the :class:`.ExcludeConstraint` construct did not + correctly forward the :paramref:`.ExcludeConstraint.info` parameter to + the superclass, causing user-defined metadata to be lost. Pull request + courtesy Wiktor Byrka. + diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py index 651f40f91a..55bfebb035 100644 --- a/lib/sqlalchemy/dialects/postgresql/ext.py +++ b/lib/sqlalchemy/dialects/postgresql/ext.py @@ -234,6 +234,11 @@ class ExcludeConstraint(ColumnCollectionConstraint): Optional string. If set, emit INITIALLY when issuing DDL for this constraint. + :param info: Optional data dictionary which will be populated into the + :attr:`.SchemaItem.info` attribute of this object. + + .. versionadded:: 2.0.50 + :param using: Optional string. If set, emit USING when issuing DDL for this constraint. Defaults to 'gist'. @@ -288,6 +293,7 @@ class ExcludeConstraint(ColumnCollectionConstraint): name=kw.get("name"), deferrable=kw.get("deferrable"), initially=kw.get("initially"), + info=kw.get("info"), ) self.using = kw.get("using", "gist") where = kw.get("where") diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 38eda0cfd2..d53db13721 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -1221,6 +1221,13 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): ")", ) + def test_exclude_constraint_info(self): + ec = ExcludeConstraint(("a", "=")) + eq_(ec.info, {}) + + ec = ExcludeConstraint(("a", "="), info={"foo": "bar"}) + eq_(ec.info, {"foo": "bar"}) + def test_exclude_constraint_min(self): m = MetaData() tbl = Table("testtbl", m, Column("room", Integer, primary_key=True))