def with_totals(self):
if not self._group_by:
raise exc.InvalidRequestError(
"Query.with_totals() can be used only with specified "
"GROUP BY, call group_by()"
)
self._with_totals = True
return self