﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18414	queryset.exists() returns False when queryset is distinct and sliced	bitrut	err	"Consider this:
{{{
User.objects.count()
3
}}}
This queryset
{{{
User.objects.all()[1:].exists()
True
}}}
produces SQL
{{{
SELECT (1) AS ""a"" FROM ""user"" LIMIT 1 OFFSET 1
}}}
so the result is correct.
But when you add `distinct()`:
{{{
User.objects.distinct()[1:].exists()
False
}}}
the SQL is
{{{
SELECT DISTINCT (1) AS ""a"" FROM ""user"" LIMIT 1 OFFSET 1
}}}
which returns nothing, so the `exists()` returns `False` which is incorrect.

`DISTINCT` narrows results to just one '''1''' and `OFFSET` omits the first result and goes to the next one which does not exist.
It's because `DISTINCT` has the higher priority than `OFFSET` in SQL.

I don't know the perfect solution. Maybe in the case of using `distinct()`, slicing and `exists()` together an exception should be thrown. Or the `exists()` function should notice this case and call `count()`, but this would lead to unexpected DB usage."	Bug	closed	Database layer (models, ORM)	1.4	Normal	fixed	orm	paluho@… bitrut@…	Accepted	1	0	0	1	0	0
