#32809: Filtering with Q and OR gets duplicated entries -------------------------------------+------------------------------------- Reporter: Ismael Jerez | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 3.2 (models, ORM) | Severity: Normal | Resolution: Keywords: queryset, Q, | Triage Stage: filtering, OR, annotation, | | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by Ismael Jerez):
* status: closed => new * resolution: needsinfo => Comment: Hi again: I am sorry for not being able to reproduce this before. Here is a simple example: 1) models.py: {{{ from django.contrib.auth.models import User from django.db import models class Example(models.Model): example_attr = models.CharField(max_length=100) users = models.ManyToManyField(User) }}} 2) I created two User's instances from admin site: - username = 'admin' - username = 'other' And two Group's instances from admin site: - name = 'Group1' - name = 'Group2' Associate Group1 and Group2 to users 'admin' and 'other' from admin site too. 3) Now the code: {{{ from example.models import Example from django.db.models import Q from django.contrib.auth.models import User, Group example = Example.objects.create(example_attr='have a nice day') user1 = User.objects.get(username='admin') user2 = User.objects.get(username='other') example.users.add(user1, user2) filters = Q(example_attr__icontains='a') | Q(users__in=User.objects.filter(groups__in=[Group.objects.get(name='Group1').pk])) print(Example.objects.count()) # This prints "1" print(Example.objects.filter(filters).count()) # This prints "2" }}} Hope this helps to reproduce the bug. This bug is happening since Django 3.2.0 until 3.2.4. Thanks in advance, Ismael. -- Ticket URL: <https://code.djangoproject.com/ticket/32809#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/072.43a29428a39000efe79d75c7e5998635%40djangoproject.com.