]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Support legacy select(<iterable>) in addition to select(<list>) in v1.4
authorOliver Rice <github@oliverrice.com>
Sat, 13 Feb 2021 19:21:55 +0000 (14:21 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 15 Feb 2021 18:25:43 +0000 (13:25 -0500)
Fixed regression where use of an arbitrary iterable with the
:func:`_sql.select` function was not working, outside of plain lists. The
forwards/backwards compatibility logic here now checks for a wider range of
incoming "iterable" types including that a ``.c`` collection from a
selectable can be passed directly. Pull request compliments of Oliver Rice.

Fixes: #5935
Closes: #5936
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5936
Pull-request-sha: 575ab3e7df30fc8da03752d102c8eeb6cb3a3e3d

Change-Id: Icd972f1078d9ea96c47a64133079f00d9b0a66f3

doc/build/changelog/unreleased_14/5935.rst [new file with mode: 0644]
lib/sqlalchemy/sql/selectable.py
test/sql/test_deprecations.py

diff --git a/doc/build/changelog/unreleased_14/5935.rst b/doc/build/changelog/unreleased_14/5935.rst
new file mode 100644 (file)
index 0000000..f7d0630
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, sql
+    :tickets: 5935
+
+    Fixed regression where use of an arbitrary iterable with the
+    :func:`_sql.select` function was not working, outside of plain lists. The
+    forwards/backwards compatibility logic here now checks for a wider range of
+    incoming "iterable" types including that a ``.c`` collection from a
+    selectable can be passed directly. Pull request compliments of Oliver Rice.
index 23fdf7e12b0bf1936f55dd646739130cb1d9c75f..ee2c4dafc59bd40bb8bf46860dddbaeb6b753a00 100644 (file)
@@ -4861,7 +4861,11 @@ class Select(
           constructs as given, as well as ORM-mapped classes.
 
         """
-        if (args and isinstance(args[0], list)) or kw:
+        if (
+            args
+            and hasattr(args[0], "__iter__")
+            and not isinstance(args[0], util.string_types + (ClauseElement,))
+        ) or kw:
             return cls.create_legacy_select(*args, **kw)
         else:
             return cls._create_future_select(*args)
index 35633a1a366c534664f9a984edc3d504cfdee068..1e5b1b995f712d8687302492416f49c1a4e943a1 100644 (file)
@@ -437,6 +437,16 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL):
             stmt = select([column("q")])
         self.assert_compile(stmt, "SELECT q")
 
+    def test_select_column_collection_argument(self):
+        t1 = table("t1", column("q"))
+
+        with testing.expect_deprecated_20(
+            r"The legacy calling style of select\(\) is deprecated "
+            "and will be removed in SQLAlchemy 2.0"
+        ):
+            stmt = select(t1.c)
+        self.assert_compile(stmt, "SELECT t1.q FROM t1")
+
     def test_select_kw_argument(self):
 
         with testing.expect_deprecated_20(