Ticket #26390: order-by-random-no-group.patch

File order-by-random-no-group.patch, 733 bytes (added by Tzu-ping Chung, 8 years ago)

Patch to SQLCompiler.get_group_by that excluds Random expressions

  • django/db/models/sql/compiler.py

    diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
    index 9fd6e83..8cb14ea 100644
    a b class SQLCompiler(object):  
    115115            # the select clause are already part of the group by.
    116116            if is_ref:
    117117                continue
    118             expressions.extend(expr.get_source_expressions())
     118            expressions.extend(
     119                exp for exp in expr.get_source_expressions()
     120                if not isinstance(exp, Random)
     121            )
    119122        having_group_by = self.having.get_group_by_cols() if self.having else ()
    120123        for expr in having_group_by:
    121124            expressions.append(expr)
Back to Top