r9701 introduces a change that leads to malformed SQL in queries that include values_list and distinct queries, at least in SQLite. A simple example:
class Database(models.Model):
name = models.TextField()
class Process(models.Model):
database = models.ForeignKey(Database)
name = models.TextField()
The query
Database.objects.filter(id__in=Process.objects.filter(id__in=(1,2)).values_list(
'database', flat=True).distinct())
produces the following SQL:
SELECT "basic_database"."id", "basic_database"."name" FROM "basic_database" WHERE
"basic_database"."id" IN (SELECT DISTINCT U0."database_id", U0."database_id" FROM
"basic_process" U0 WHERE U0."id" IN (1, 2)) LIMIT 21
where U0."database_id" is repeated, and produces an error:
OperationalError: only a single result allowed for a SELECT that is part of an expression
Unfortunately, this is the limit of my Python knowledge, so I don't have a patch to correct this problem.
The query functions perfectly in r9700 and earlier.