Should be unneeded with Python 2.7 and up. Added some unicode_literals along the way.
In the combination of .values().aggregate() the aggregate_select_mask didn't include the aggregates added. This resulted in bogus query. Thanks to Trac alias debanshuk for report.