﻿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
32068	Raise a descriptive error on get() with filters operation following QuerySet.union(), intersection(), and difference().	Timo Ludwig	Hasan Ramezani	"The QuerySet resulting from q1.difference(q2) does not allow to retrieve one specific object of that resulting QuerySet.

Minimal example:

models.py
{{{
from django.db import models

class Test(models.Model):
    name = models.CharField(max_length=30)
}}}

python manage.py shell
{{{
>>> from test.models import Test
>>> qs1 = Test.objects.all()
>>> qs1
<QuerySet [<Test: Test object (1)>, <Test: Test object (2)>, <Test: Test object (3)>]>
>>> qs2 = Test.objects.filter(id=1)
>>> qs2
<QuerySet [<Test: Test object (1)>]>
>>> qs3 = qs1.difference(qs2)
>>> qs3
<QuerySet [<Test: Test object (2)>, <Test: Test object (3)>]>
>>> qs3.get(id=2)
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""/lib/python3.8/site-packages/django/db/models/query.py"", line 433, in get
    raise self.model.MultipleObjectsReturned(
test.models.Test.MultipleObjectsReturned: get() returned more than one Test -- it returned 2!
}}}

Django version: 3.1.2
Python version: 3.8.5
OS: Arch Linux

I also experienced this in the regular request/view-context, with other Django versions (2.2) and other python versions (3.7).
Sorry if this is the expected behavior, a known bug or if I missed something which changes the behavior only on my system.
If you need more information, I'll be happy to assist."	Cleanup/optimization	closed	Database layer (models, ORM)	3.1	Normal	fixed	queryset, difference	Hasan Ramezani	Accepted	1	0	0	0	1	0
