﻿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
32809	Filtering with Q and OR gets duplicated entries	Ismael Jerez	nobody	"Hi:

Django version: 3.2.4
Python version: 3.8

I cannot reproduce this bug in a simple example, so I can only show you screenshots from my Pycharm Debug Tool, I am sorry.

I have one queryset with 3 objects which contains annotations, CharField and ManyToManyField attributes. Then I filter by a query using Q like this: 
{{{
(OR: ('created_date_dt_custom__icontains', 'a'), ('id__icontains', 'a'), ('title__unaccent__icontains', 'a'), ('created_date_dt_custom__icontains', 'a'), ('id__icontains', 'a'), ('title__unaccent__icontains', 'a'), ('promoters__in', <QuerySet [<User: admin>, <User: u********>]>))
}}}
And gets a queryset with 4 objects as a result, one of the objects is duplicated. If I delete the last filter ('promoters__in', <QuerySet [<User: admin>, <User: u********>]>) it works fine, so the problem is on this filter or maybe the concatenation of filters with this kind.

I have no problem on Django version ~= 2.

Here are the screenshots of my debug tool showing the problem:
- Screenshot of the code: https://i.ibb.co/Fnb53rn/ss1.png
- Screenshot of debug tool with variable values (Project object (19) duplicated): https://i.ibb.co/b34FwSM/ss2.png

Thank you in advance, hope it is fixed soon,
Ismael.

"	Bug	closed	Database layer (models, ORM)	3.2	Normal	needsinfo	queryset, Q, filtering, OR, annotation, |		Unreviewed	0	0	0	0	0	0
