From 61f69848c994a8702850c4c93d8156eb064b3b6c Mon Sep 17 00:00:00 2001 From: Bendeguz Csirmaz Date: Fri, 29 Mar 2024 22:26:10 +0800 Subject: [PATCH] Fix --- django/db/models/fields/composite.py | 18 +++++++++--------- tests/composite_pk/test_get.py | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/django/db/models/fields/composite.py b/django/db/models/fields/composite.py index 0dd361f304f6..540114c46ab8 100644 --- a/django/db/models/fields/composite.py +++ b/django/db/models/fields/composite.py @@ -11,15 +11,15 @@ class TupleExact(Exact): def get_prep_lookup(self): if not isinstance(self.lhs, Cols): raise ValueError( - "The left-hand side of TupleExact lookups must be an instance of Cols" + "The left-hand side of the 'exact' lookup must be an instance of Cols" ) if not isinstance(self.rhs, Iterable): raise ValueError( - "The right-hand side of TupleExact lookups must be an iterable" + "The right-hand side of the 'exact' lookup must be an iterable" ) if len(list(self.lhs)) != len(list(self.rhs)): raise ValueError( - "The left-hand side and right-hand side of TupleExact lookups must " + "The left-hand side and right-hand side of the 'exact' lookup must " "have the same number of elements" ) @@ -38,21 +38,21 @@ class TupleIn(In): def get_prep_lookup(self): if not isinstance(self.lhs, Cols): raise ValueError( - "The left-hand side of TupleIn lookups must be an instance of Cols" + "The left-hand side of the 'in' lookup must be an instance of Cols" ) if not isinstance(self.rhs, Iterable): raise ValueError( - "The right-hand side of TupleIn lookups must be an iterable" + "The right-hand side of the 'in' lookup must be an iterable" ) if not all(isinstance(vals, Iterable) for vals in self.rhs): raise ValueError( - "The right-hand side of TupleIn lookups must be an iterable of " + "The right-hand side of the 'in' lookup must be an iterable of " "iterables" ) - lhs_len = len(list(self.lhs)) - if not all(lhs_len == len(list(vals)) for vals in self.rhs): + lhs_len = len(tuple(self.lhs)) + if not all(lhs_len == len(tuple(vals)) for vals in self.rhs): raise ValueError( - "The left-hand side and right-hand side of TupleIn lookups must " + "The left-hand side and right-hand side of the 'in' lookup must " "have the same number of elements" ) diff --git a/tests/composite_pk/test_get.py b/tests/composite_pk/test_get.py index 90fe3c9c07a5..e9e360e8f7f2 100644 --- a/tests/composite_pk/test_get.py +++ b/tests/composite_pk/test_get.py @@ -200,28 +200,28 @@ def test_get_or_create_user_by_pk(self): def test_lookup_errors(self): with self.assertRaisesMessage( - ValueError, "The right-hand side of TupleExact lookups must be an iterable" + ValueError, "The right-hand side of the 'exact' lookup must be an iterable" ): Comment.objects.get(pk=1) with self.assertRaisesMessage( ValueError, - "The left-hand side and right-hand side of TupleExact " - "lookups must have the same number of elements", + "The left-hand side and right-hand side of the 'exact' " + "lookup must have the same number of elements", ): Comment.objects.get(pk=(1, 2, 3)) with self.assertRaisesMessage( - ValueError, "The right-hand side of TupleIn lookups must be an iterable" + ValueError, "The right-hand side of the 'in' lookup must be an iterable" ): Comment.objects.get(pk__in=1) with self.assertRaisesMessage( ValueError, - "The right-hand side of TupleIn lookups must be an iterable " + "The right-hand side of the 'in' lookup must be an iterable " "of iterables", ): Comment.objects.get(pk__in=(1, 2, 3)) with self.assertRaisesMessage( ValueError, - "The left-hand side and right-hand side of TupleIn lookups must " + "The left-hand side and right-hand side of the 'in' lookup must " "have the same number of elements", ): Comment.objects.get(pk__in=((1, 2, 3),))