From 05f28ba2fb6b9fe1e36748bb16969afc8375a9fb Mon Sep 17 00:00:00 2001 From: Iuri Diniz Date: Fri, 29 Jul 2016 12:54:22 -0400 Subject: Allow None to cancel Query.group_by() This replicates the same behavior as order_by(). order_by() will also be updated to deprecate passing of False as this is no longer functionally different than passing None. Change-Id: I2fc05d0317d28b6c83373769a48f7eea32d56290 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/297 --- lib/sqlalchemy/orm/query.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index c1daaaf07..c5ecbaffe 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1549,7 +1549,21 @@ class Query(object): @_generative(_no_statement_condition, _no_limit_offset) def group_by(self, *criterion): """apply one or more GROUP BY criterion to the query and return - the newly resulting :class:`.Query`""" + the newly resulting :class:`.Query` + + All existing GROUP BY settings can be suppressed by + passing ``None`` - this will suppress any GROUP BY configured + on mappers as well. + + .. versionadded:: 1.1 GROUP BY can be cancelled by passing None, + in the same way as ORDER BY. + + """ + + if len(criterion) == 1: + if criterion[0] is None: + self._group_by = False + return criterion = list(chain(*[_orm_columns(c) for c in criterion])) criterion = self._adapt_col_list(criterion) -- cgit v1.2.1