SQLAlchemy\'s Query.distinct method is behaving inconsistently:
>>> [tag.name for tag in session.query(Tag).all()]
[u\'Male\', u\'Male\', u\'Ninja\'
When you use session.query(Tag) you alway query for the whole Tag object, so if your table contains other columns it won't work.
Let's assume there is an id column, then the query
sess.query(Tag).distinct(Tag.name)
will produce:
SELECT DISTINCT tag.id AS tag_id, tag.name AS tag_name FROM tag
The argument to the distinct clause is ignored completely.
If you really only want the distinct names from the table, you must explicitly select only the names:
sess.query(Tag.name).distinct()
produces:
SELECT DISTINCT tag.name AS tag_name FROM tag