coleifer/peewee — Issue #36: group_by() broken for queries without aliases
Author: awahlig
Created: 2011-12-30 23:03:54+00:00
State: open

This code:

```python
from peewee import *

class Message(Model):
author = CharField()
body = TextField()

print Message.select().group_by('author').sql()
```

Throws this exception:

Traceback (most recent call last):
File "test.py", line 7, in
print Message.select().group_by('author').sql()
File "peewee.py", line 1216, in sql
group_by = ', '.join(group_by)
TypeError: sequence item 0: expected string, tuple found

This part of SelectQuery.sql() seems responsible:

```python
if self.use_aliases():
(...)
else:
group_by = [c[1] for c in self._group_by]
```

c[1] is a sequence of field names, not a single field name, so str.join() fails. The code used when use_aliases() returns True seems to work better.