From: Mike Bayer Date: Fri, 19 Sep 2025 19:18:39 +0000 (-0400) Subject: fix tests for aggregate_order_by X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9a6854223c60b63a463d4b0ad79c990c0fd29630;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix tests for aggregate_order_by forgot this doesnt work on sqlite older than 3.44 Change-Id: Icebc2ffaceb078a436a8f61ba583bc05b77f680d --- diff --git a/doc/build/tutorial/data_select.rst b/doc/build/tutorial/data_select.rst index 111ddaac1f..51d82279aa 100644 --- a/doc/build/tutorial/data_select.rst +++ b/doc/build/tutorial/data_select.rst @@ -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`. diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py index 6c1d3918a2..7ed922efca 100644 --- a/lib/sqlalchemy/testing/requirements.py +++ b/lib/sqlalchemy/testing/requirements.py @@ -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 diff --git a/test/requirements.py b/test/requirements.py index 8ba81f389a..931077d672 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -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( diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py index b569c41ca3..19c8930731 100644 --- a/test/sql/test_functions.py +++ b/test/sql/test_functions.py @@ -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,