mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #35690 -- Errored nicely when using in_bulk() with a values() or values_list() queryset.
This commit is contained in:
parent
fd1dd76778
commit
e4a2e22ddb
@ -1101,6 +1101,8 @@ class QuerySet(AltersData):
|
|||||||
"""
|
"""
|
||||||
if self.query.is_sliced:
|
if self.query.is_sliced:
|
||||||
raise TypeError("Cannot use 'limit' or 'offset' with in_bulk().")
|
raise TypeError("Cannot use 'limit' or 'offset' with in_bulk().")
|
||||||
|
if not issubclass(self._iterable_class, ModelIterable):
|
||||||
|
raise TypeError("in_bulk() cannot be used with values() or values_list().")
|
||||||
opts = self.model._meta
|
opts = self.model._meta
|
||||||
unique_fields = [
|
unique_fields = [
|
||||||
constraint.fields[0]
|
constraint.fields[0]
|
||||||
|
@ -327,6 +327,13 @@ class LookupTests(TestCase):
|
|||||||
with self.assertRaisesMessage(TypeError, msg):
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
Article.objects.all()[0:5].in_bulk([self.a1.id, self.a2.id])
|
Article.objects.all()[0:5].in_bulk([self.a1.id, self.a2.id])
|
||||||
|
|
||||||
|
def test_in_bulk_not_model_iterable(self):
|
||||||
|
msg = "in_bulk() cannot be used with values() or values_list()."
|
||||||
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
|
Author.objects.values().in_bulk()
|
||||||
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
|
Author.objects.values_list().in_bulk()
|
||||||
|
|
||||||
def test_values(self):
|
def test_values(self):
|
||||||
# values() returns a list of dictionaries instead of object instances --
|
# values() returns a list of dictionaries instead of object instances --
|
||||||
# and you can specify which fields you want to retrieve.
|
# and you can specify which fields you want to retrieve.
|
||||||
|
Loading…
Reference in New Issue
Block a user