-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #373 -- Added CompositePrimaryKey-based Meta.primary_key. #18056
base: main
Are you sure you want to change the base?
Changes from 1 commit
4be1c68
cee213d
e2d8868
259605a
9e01443
fa4af00
8354bd0
d20f8e0
dcd78fc
3576dec
1ef76e4
3d0dcf3
6a2bb92
a2ec10c
3071ad9
b7179b6
cb4f300
6922337
b7b9580
9b17831
6285cff
22d6c9d
ad51da4
9c9e57d
c8f796e
26fb669
87b1a23
389daa9
2515066
350c58d
220b3ed
b9a8143
141b27d
926822f
ac29218
0b194eb
b6727d2
21d48d5
b839b2b
006736c
3bf4004
90a8d43
7bc3f40
f4db656
e7deac6
e15f55d
79bf5e8
92f2807
c5c5239
8e408b6
69143d9
586434c
0478d46
23e0e0b
a9ef232
694fcc8
b49ea71
9fbb766
96156dd
13c0053
9ce6781
2f24f77
2c8d38c
cff46d5
39a2a09
2478e14
76191b5
208a457
b74f3ef
70fd4be
4caee01
272184d
0cf5ec0
6e8e116
cd38f37
7f828b3
c581bb6
370bbc9
bf4f433
88f44a6
6585413
f76dc06
d9bf07c
5255677
9505494
451e601
0857b42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,30 +84,20 @@ | |
|
||
def test_lookup_errors(self): | ||
with self.assertRaisesMessage( | ||
ValueError, | ||
"The right-hand side of the 'exact' lookup must be a tuple or a list", | ||
ValueError, "'primary_key' must be a tuple or a list" | ||
): | ||
Comment.objects.get(pk=1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if this could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is possible unfortunately, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about this?
|
||
with self.assertRaisesMessage( | ||
ValueError, | ||
"The left-hand side and right-hand side of the 'exact' " | ||
"lookup must have the same number of elements", | ||
ValueError, f"'primary_key' must have 2 elements" | ||
): | ||
Comment.objects.get(pk=(1, 2, 3)) | ||
with self.assertRaisesMessage( | ||
ValueError, | ||
"The right-hand side of the 'in' lookup must be a tuple or a list", | ||
ValueError, "'primary_key' must be a tuple or a list" | ||
): | ||
Comment.objects.get(pk__in=1) | ||
with self.assertRaisesMessage( | ||
ValueError, | ||
"The right-hand side of the 'in' lookup must be a collection " | ||
"of tuples or lists", | ||
ValueError, "'primary_key' must be a collection of tuples or lists" | ||
): | ||
Comment.objects.get(pk__in=(1, 2, 3)) | ||
with self.assertRaisesMessage( | ||
ValueError, | ||
"The left-hand side and right-hand side of the 'in' lookup must " | ||
"have the same number of elements", | ||
): | ||
with self.assertRaisesMessage(ValueError, "'primary_key' must have 2 elements"): | ||
Comment.objects.get(pk__in=((1, 2, 3),)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is quite clear. If the
pk
has two component fields, but the lookup ispk__in=([1, 2], [3])
we will raise an error'pk' must have 2 elements
but the tuple does have two elements. I'm not sure what to suggest instead though - it's tricky...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some changes, let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?