]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixes: #7295
authorjonathan vanasco <jonathan@2xlp.com>
Fri, 5 Nov 2021 16:38:30 +0000 (12:38 -0400)
committerjonathan vanasco <jonathan@2xlp.com>
Sat, 6 Nov 2021 16:34:49 +0000 (12:34 -0400)
Fixed issue in ``Table``` object where: param:`implicit_returning` was not
compatible with: param:`extend_existing`.
Change-Id: I16f4ab585d82f5691a3fed9eba04b84730a8a59e

doc/build/changelog/unreleased_14/7295.rst [new file with mode: 0644]
lib/sqlalchemy/sql/schema.py
test/sql/test_metadata.py

diff --git a/doc/build/changelog/unreleased_14/7295.rst b/doc/build/changelog/unreleased_14/7295.rst
new file mode 100644 (file)
index 0000000..058c9d1
--- /dev/null
@@ -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`.
index e45e22564d828305202feaf7be57350ff55c1611..c3c8ffb2cec1257699624688a7f54f8899760344 100644 (file)
@@ -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:
index 08502b8bbebbc4ffe3050466f39f2e675d045cbf..bd921364795c54cb7cd7b896b0844a01520f2e46 100644 (file)
@@ -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):