]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Added back ``items`` and ``values`` to ``ColumnCollection`` class.
authorFederico Caselli <cfederico87@gmail.com>
Tue, 16 Mar 2021 22:56:28 +0000 (23:56 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Tue, 16 Mar 2021 23:31:59 +0000 (00:31 +0100)
Fixes: #6068
Change-Id: Idb42c864e17c02d7b89cffa667dcf853ec93e5c2

doc/build/changelog/unreleased_14/6068.rst [new file with mode: 0644]
lib/sqlalchemy/sql/base.py
test/base/test_utils.py

diff --git a/doc/build/changelog/unreleased_14/6068.rst b/doc/build/changelog/unreleased_14/6068.rst
new file mode 100644 (file)
index 0000000..240254f
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, regression
+    :tickets: 6068
+
+    Added back ``items`` and ``values`` to ``ColumnCollection`` class.
+    The regression was introduced while adding support for duplicate
+    columns in from clauses and selectable in ticket #4753.
+
index c76c9ae148989d0c6adb34659c5cdb39566e9672..726800717c19a076c8823a9f826a032bb61a3d70 100644 (file)
@@ -1126,6 +1126,12 @@ class ColumnCollection(object):
     def keys(self):
         return [k for (k, col) in self._collection]
 
+    def values(self):
+        return [col for (k, col) in self._collection]
+
+    def items(self):
+        return list(self._collection)
+
     def __bool__(self):
         return bool(self._collection)
 
index a00fbd0186297272606b9a17223368c2d82eb919..b602811ab09a173fdb6eebd44f4c79c1788696f6 100644 (file)
@@ -464,11 +464,39 @@ class ColumnCollectionCommon(testing.AssertsCompiledSQL):
         cc = self._column_collection(
             columns=[("c1", c1), ("foo", c2), ("c3", c3)]
         )
-        eq_(cc.keys(), ["c1", "foo", "c3"])
+        keys = cc.keys()
+        eq_(keys, ["c1", "foo", "c3"])
+        ne_(id(keys), id(cc.keys()))
 
         ci = cc.as_immutable()
         eq_(ci.keys(), ["c1", "foo", "c3"])
 
+    def test_values(self):
+        c1, c2, c3 = sql.column("c1"), sql.column("c2"), sql.column("c3")
+        c2.key = "foo"
+        cc = self._column_collection(
+            columns=[("c1", c1), ("foo", c2), ("c3", c3)]
+        )
+        val = cc.values()
+        eq_(val, [c1, c2, c3])
+        ne_(id(val), id(cc.values()))
+
+        ci = cc.as_immutable()
+        eq_(ci.values(), [c1, c2, c3])
+
+    def test_items(self):
+        c1, c2, c3 = sql.column("c1"), sql.column("c2"), sql.column("c3")
+        c2.key = "foo"
+        cc = self._column_collection(
+            columns=[("c1", c1), ("foo", c2), ("c3", c3)]
+        )
+        items = cc.items()
+        eq_(items, [("c1", c1), ("foo", c2), ("c3", c3)])
+        ne_(id(items), id(cc.items()))
+
+        ci = cc.as_immutable()
+        eq_(ci.items(), [("c1", c1), ("foo", c2), ("c3", c3)])
+
     def test_key_index_error(self):
         cc = self._column_collection(
             columns=[