-
Notifications
You must be signed in to change notification settings - Fork 7
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
add ObjectIdField #187
base: main
Are you sure you want to change the base?
add ObjectIdField #187
Conversation
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 think an ObjectIdField.get_prep_value() is needed. It can be exercised with a querying test that uses lookup with a string ObjectId.
1eef512
to
0570518
Compare
This comment was marked as resolved.
This comment was marked as resolved.
680f1b0
to
55f56ed
Compare
Maybe you are right, I will create some unit test to covers that. |
f5094fe
to
3e817db
Compare
Done. |
Looks like there was a caught failure in two of the tests? I don't see the equivalent failured in github, so I'm going to re-run it |
We don't need to worry about evergreen. It fails as expected because it's not using Emanuel's Django branch that'll be merged with this patch. |
I don't think we want to allow integer for ObjectIdField. This was only done on ObjectIdAutoField for compatibility with Django's test suite. and there's an Jira ticket to revisit this decision since it seems likely to be problematic in the long run. |
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.
Sorry, I thought I linked to an example of the sort of tests I had in mind. See model_fields/test_jsonfield.TestQuerying
. Maybe what you have written is fine but it's perhaps more t than necessary. And like I said in another comment, all the loops and subTest are difficult to read and I fear would be somewhat difficult to debug if they fail.
tests/queries_/test_objectid.py
Outdated
self.assertSequenceEqual(union_qs, [self.t3, self.t4]) | ||
|
||
def test_invalid_object_id(self): | ||
"""Combine queries using union""" |
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.
No union in sight in this test.
tests/queries_/test_objectid.py
Outdated
self.assertSequenceEqual(qs, [self.t3, self.t4]) | ||
|
||
def test_union_children_to_select_parents(self): | ||
"""Union query to select parents of children based on group_id""" |
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.
No union in sight in this test.
def test_to_python(self): | ||
f = ObjectIdField() | ||
expected = ObjectId("1" * 24) | ||
for value in ["1" * 24, ObjectId("1" * 24)]: |
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'd prefer separate tests or a string of to_python()
calls without the loops and subTest, e.g.
def test_to_python(self):
self.assertIsNone(models.UUIDField().to_python(None))
def test_to_python_int_values(self):
self.assertEqual(
models.UUIDField().to_python(0),
uuid.UUID("00000000-0000-0000-0000-000000000000"),
)
# Works for integers less than 128 bits.
self.assertEqual(
models.UUIDField().to_python((2**128) - 1),
uuid.UUID("ffffffff-ffff-ffff-ffff-ffffffffffff"),
)
I think the current way is too hard on the eyes.
I agree that is not a good idea. I faced the same problem in many tests. I can make some changes in the test´s models in order to avoid integers instead of objectId. |
🤔 They are indeed difficult to debug, and the Django test suite is full of them 😬. However, I think I can write multiple tests or a few tests with more steps instead of using subtests. |
fixes #161