From: jonathan vanasco Date: Fri, 5 Nov 2021 16:38:30 +0000 (-0400) Subject: Fixes: #7295 X-Git-Tag: rel_2_0_0b1~660^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5836f29f5612d5f653683644566a57c47291b5d;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fixes: #7295 Fixed issue in ``Table``` object where: param:`implicit_returning` was not compatible with: param:`extend_existing`. Change-Id: I16f4ab585d82f5691a3fed9eba04b84730a8a59e --- diff --git a/doc/build/changelog/unreleased_14/7295.rst b/doc/build/changelog/unreleased_14/7295.rst new file mode 100644 index 0000000000..058c9d16a5 --- /dev/null +++ b/doc/build/changelog/unreleased_14/7295.rst @@ -0,0 +1,9 @@ +.. change:: + :tags: bug, schema + :tickets: 7295 + + Fixed issue in :class:`.Table` where the + :paramref:`.Table.implicit_returning` parameter would not be + accommodated correctly when passed along with + :paramref:`.Table.extend_existing` to augment an existing + :class:`.Table`. diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index e45e22564d..c3c8ffb2ce 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -763,25 +763,25 @@ class Table(DialectKWArgs, SchemaItem, TableClause): ) include_columns = kwargs.pop("include_columns", None) - - resolve_fks = kwargs.pop("resolve_fks", True) - if include_columns is not None: for c in self.c: if c.name not in include_columns: self._columns.remove(c) + resolve_fks = kwargs.pop("resolve_fks", True) + for key in ("quote", "quote_schema"): if key in kwargs: raise exc.ArgumentError( "Can't redefine 'quote' or 'quote_schema' arguments" ) - if "comment" in kwargs: - self.comment = kwargs.pop("comment", None) - - if "info" in kwargs: - self.info = kwargs.pop("info") + # update `self` with these kwargs, if provided + self.comment = kwargs.pop("comment", self.comment) + self.implicit_returning = kwargs.pop( + "implicit_returning", self.implicit_returning + ) + self.info = kwargs.pop("info", self.info) if autoload: if not autoload_replace: diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 08502b8bbe..bd92136479 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -1923,6 +1923,31 @@ class TableTest(fixtures.TestBase, AssertsCompiledSQL): ): Table("foo", MetaData(), must_exist=True) + @testing.combinations( + ("comment", ("A", "B", "A")), + ("implicit_returning", (True, False, True)), + ("info", ({"A": 1}, {"A": 2}, {"A": 1})), + ) + def test_extend_attributes(self, attrib, attrib_values): + """ + ensure `extend_existing` is compatible with simple attributes + """ + metadata = MetaData() + for counter, _attrib_value in enumerate(attrib_values): + _extend_existing = True if (counter > 0) else False + _kwargs = { + "extend_existing": _extend_existing, + attrib: _attrib_value, + } + table_a = Table( + "a", + metadata, + Column("foo", String, primary_key=True), + **_kwargs + ) + eq_(getattr(table_a, attrib), _attrib_value) + eq_(getattr(metadata.tables["a"], attrib), _attrib_value) + class PKAutoIncrementTest(fixtures.TestBase): def test_multi_integer_no_autoinc(self):