Skip to content
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

Merged
merged 2 commits into from
Dec 10, 2024
Merged

add ObjectIdField #187

merged 2 commits into from
Dec 10, 2024

Conversation

WaVEV
Copy link
Collaborator

@WaVEV WaVEV commented Nov 17, 2024

fixes #161

.github/workflows/test-python.yml Outdated Show resolved Hide resolved
Jibola

This comment was marked as resolved.

timgraham

This comment was marked as resolved.

@timgraham timgraham changed the title Add object id field add ObjectIdField Nov 18, 2024
Copy link
Collaborator

@timgraham timgraham left a 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.

django_mongodb/fields/objectid.py Outdated Show resolved Hide resolved
django_mongodb/fields/objectid.py Show resolved Hide resolved
tests/model_fields_/test_objectidfield.py Outdated Show resolved Hide resolved
django_mongodb/fields/auto.py Outdated Show resolved Hide resolved
@WaVEV WaVEV force-pushed the Add-ObjectIdField branch from 1eef512 to 0570518 Compare November 19, 2024 01:12
@timgraham

This comment was marked as resolved.

@WaVEV WaVEV force-pushed the Add-ObjectIdField branch from 680f1b0 to 55f56ed Compare November 20, 2024 02:51
@WaVEV
Copy link
Collaborator Author

WaVEV commented Nov 21, 2024

I think an ObjectIdField.get_prep_value() is needed. It can be exercised with a querying test that uses lookup with a string ObjectId.

Maybe you are right, I will create some unit test to covers that.

@WaVEV WaVEV force-pushed the Add-ObjectIdField branch from f5094fe to 3e817db Compare November 23, 2024 18:58
@WaVEV
Copy link
Collaborator Author

WaVEV commented Nov 23, 2024

I think an ObjectIdField.get_prep_value() is needed. It can be exercised with a querying test that uses lookup with a string ObjectId.

Done.

@Jibola
Copy link
Collaborator

Jibola commented Nov 25, 2024

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
https://evergreen.mongodb.com/task_log_raw/django_mongodb_tests_run_tests_patch_36c57187de430ab4313e8db5c3ce8ab2ab569f5b_6742512f8f2d9a000730e871_24_11_23_22_03_28/0?type=T#L18115

@timgraham
Copy link
Collaborator

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.

@timgraham
Copy link
Collaborator

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.

Copy link
Collaborator

@timgraham timgraham left a 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 Show resolved Hide resolved
tests/queries_/test_objectid.py Outdated Show resolved Hide resolved
tests/model_fields_/test_objectidfield.py Outdated Show resolved Hide resolved
@WaVEV
Copy link
Collaborator Author

WaVEV commented Nov 26, 2024

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.

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.

@WaVEV
Copy link
Collaborator Author

WaVEV commented Nov 26, 2024

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.

🤔 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.

@timgraham
Copy link
Collaborator

Looking at the test failures after my edits, it might be that we don't want to make the proposed change in the Django test suite and just leave those tests as skipped/invalid on MongoDB. Do the new queries tests you wrote cover the issue? If not, we can add those to our test suite (without modifying the models in Django's test suite which breaks other things due to the fact that ObjectIdField doesn't accept integers).

@WaVEV
Copy link
Collaborator Author

WaVEV commented Dec 6, 2024

Looking at the test failures after my edits, it might be that we don't want to make the proposed change in the Django test suite and just leave those tests as skipped/invalid on MongoDB. Do the new queries tests you wrote cover the issue? If not, we can add those to our test suite (without modifying the models in Django's test suite which breaks other things due to the fact that ObjectIdField doesn't accept integers).

I agree with that. I will add test to cover the issue.

@timgraham timgraham dismissed Jibola’s stale review December 7, 2024 23:56

comments addressed

@timgraham
Copy link
Collaborator

We failed to consider save/load tests as well as forms support. I adapt some tests from UUIDField but the current code isn't entirely consistent with it. It seems Django's built-in model fields aren't entirely consistent with respect to the exceptions they raise in each method. I'll return to this next week with fresh eyes.

WaVEV and others added 2 commits December 10, 2024 17:58
Co-authored-by: Tim Graham <[email protected]>
Updating the affected models to use ObjectIdField breaks other tests.
@timgraham timgraham merged commit 9ec493f into mongodb-labs:main Dec 10, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QuerySet.filter() in lookup doesn't return any results when subquery returns ObjectId
3 participants