]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix tests for aggregate_order_by
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Sep 2025 19:18:39 +0000 (15:18 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Sep 2025 19:18:39 +0000 (15:18 -0400)
forgot this doesnt work on sqlite older than 3.44

Change-Id: Icebc2ffaceb078a436a8f61ba583bc05b77f680d

doc/build/tutorial/data_select.rst
lib/sqlalchemy/testing/requirements.py
test/requirements.py
test/sql/test_functions.py

index 111ddaac1f056242b1a795c69deea87067c83b1c..51d82279aac0f639fc8c831ab824d8f3c3527778 100644 (file)
@@ -1666,25 +1666,18 @@ function which produces a JSON array.  Ordering of the elements passed
 to these functions is supported using the :meth:`_functions.FunctionElement.aggregate_order_by`
 method, which will render ORDER BY in the appropriate part of the function::
 
-    >>> with engine.connect() as conn:
-    ...     result = conn.execute(
-    ...         select(
-    ...             func.group_concat(user_table.c.name).aggregate_order_by(
-    ...                 user_table.c.name.desc()
-    ...             )
-    ...         )
-    ...     )
-    ...     print(result.all())
-    {execsql}BEGIN (implicit)
-    SELECT group_concat(user_account.name ORDER BY user_account.name DESC) AS group_concat_1
+    >>> stmt = select(
+    ...     func.group_concat(user_table.c.name).aggregate_order_by(user_table.c.name.desc())
+    ... )
+    >>> print(stmt)
+    {printsql}SELECT group_concat(user_account.name ORDER BY user_account.name DESC) AS group_concat_1
     FROM user_account
-    [...] ()
-    {stop}[('spongebob,sandy,patrick',)]
-    {printsql}ROLLBACK{stop}
 
 .. tip:: The above demonstration shows use of the ``group_concat()`` function
-   on SQLite to concatenate strings.  As this type of function varies
-   highly on all backends, SQLAlchemy also provides a backend-agnostic
+   available on SQLite which concatenates strings; the ORDER BY feature
+   for SQLite requires SQLite 3.44.0 or greater.  As the availability, name
+   and specific syntax of the string aggregation functions varies
+   widely by backend, SQLAlchemy also provides a backend-agnostic
    version specifically for concatenating strings called
    :func:`_functions.aggregate_strings`.
 
index 6c1d3918a2e385a3b0730465bcd3b402c592f2d2..7ed922efca6575402ac151526420ebe8c0367c0e 100644 (file)
@@ -1249,6 +1249,14 @@ class SuiteRequirements(Requirements):
         """
         return exclusions.open()
 
+    @property
+    def aggregate_order_by(self):
+        """target database can use ORDER BY or equivalent in an aggregate
+        function, and dialect supports aggregate_order_by().
+
+        """
+        return exclusions.closed()
+
     @property
     def recursive_fk_cascade(self):
         """target database must support ON DELETE CASCADE on a self-referential
index 8ba81f389aba78ae83714c42f9c4518981860601..931077d6727605ce1119d99cb1f68a8e0169e96f 100644 (file)
@@ -1143,6 +1143,24 @@ class DefaultRequirements(SuiteRequirements):
 
         return skip_if(["mssql", "sqlite"])
 
+    @property
+    def aggregate_order_by(self):
+        """target database can use ORDER BY or equivalent in an aggregate
+        function, and dialect supports aggregate_order_by().
+
+        """
+
+        return only_on(
+            [
+                "postgresql",
+                "sqlite >= 3.44.0",
+                "mysql",
+                "mariadb",
+                "oracle",
+                "mssql",
+            ]
+        )
+
     @property
     def tuple_valued_builtin_functions(self):
         return only_on(
index b569c41ca3b2ee15692114adb018865e5df66766..19c8930731bed6b5e6aeaa9844b117d9d17b2b43 100644 (file)
@@ -1431,7 +1431,9 @@ class ExecuteTest(fixtures.TestBase):
 
     @testing.variation("unicode_value", [True, False])
     @testing.variation("unicode_separator", [True, False])
-    @testing.variation("use_order_by", [True, False])
+    @testing.variation(
+        "use_order_by", [(True, testing.requires.aggregate_order_by), False]
+    )
     @testing.only_on(
         ["postgresql", "sqlite", "mysql", "mariadb", "oracle", "mssql"]
     )
@@ -1498,9 +1500,7 @@ class ExecuteTest(fixtures.TestBase):
 
         eq_(value, expected)
 
-    @testing.only_on(
-        ["postgresql", "sqlite", "mysql", "mariadb", "oracle", "mssql"]
-    )
+    @testing.requires.aggregate_order_by
     def test_aggregate_order_by(
         self,
         connection,