Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
csirmazbendeguz committed Mar 29, 2024
1 parent 0ffeaf3 commit 61f6984
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions django/db/models/fields/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"
)

Expand Down
12 changes: 6 additions & 6 deletions tests/composite_pk/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),))

0 comments on commit 61f6984

Please sign in to comment.