Skip to content

Conversation

aclark4life
Copy link
Contributor

For use with django-mongodb e.g.


(.venv) alex.clark@Mac tmp.0F48BsWTyQ % python manage.py sqlmigrate auth 0001
System check identified some issues:

WARNINGS:
?: (staticfiles.W004) The directory '/private/var/folders/5t/d3llmfm54v3dg712_4pks3lm0000gn/T/tmp.0F48BsWTyQ/frontend/build' in the STATICFILES_DIRS setting does not exist.
--
-- Create model Permission
--
db.create_collection('auth_permission')
db.auth_permission.create_indexes([IndexModel({'name': 'auth_permission_content_type_id_2f476e4b', 'key': {'content_type_id': 1}})])
--
-- Create model Group
--
db.create_collection('auth_group')
db.create_collection('auth_group_permissions')
db.auth_group_permissions.create_indexes([IndexModel({'name': 'auth_group_permissions_group_id_b120cbf9', 'key': {'group_id': 1}})])
db.auth_group_permissions.create_indexes([IndexModel({'name': 'auth_group_permissions_permission_id_84c5c92e', 'key': {'permission_id': 1}})])
--
-- Create model User
--
db.create_collection('auth_user')
db.create_collection('auth_user_groups')
db.auth_user_groups.create_indexes([IndexModel({'name': 'auth_user_groups_user_id_6a12ed8b', 'key': {'user_id': 1}})])
db.auth_user_groups.create_indexes([IndexModel({'name': 'auth_user_groups_group_id_97559544', 'key': {'group_id': 1}})])
db.create_collection('auth_user_user_permissions')
db.auth_user_user_permissions.create_indexes([IndexModel({'name': 'auth_user_user_permissions_user_id_a95ead1b', 'key': {'user_id': 1}})])
db.auth_user_user_permissions.create_indexes([IndexModel({'name': 'auth_user_user_permissions_permission_id_1fbb5f2c', 'key': {'permission_id': 1}})])

@timgraham
Copy link
Collaborator

There are quite a lot of possible IndexModel kwargs besides the ones hardcoded here. Looking at IndexModel.__init__()), it appears that besides the key/keys rename, all other document keys can be be used unaltered in __repr__().

@aclark4life
Copy link
Contributor Author

There are quite a lot of possible IndexModel kwargs besides the ones hardcoded here. Looking at IndexModel.__init__()), it appears that besides the key/keys rename, all other document keys can be be used unaltered in __repr__().

Thanks, fixed. I'm going to add some tests for the other known kwargs.

@ShaneHarvey
Copy link
Member

ShaneHarvey commented Oct 14, 2024

Ruff wants you to use f-string or .format() instead:

ruff.....................................................................Failed
- hook id: ruff
- exit code: 1
- files were modified by this hook

pymongo/operations.py:777:16: UP031 Use format specifiers instead of percent format
pymongo/operations.py:782:21: UP031 Use format specifiers instead of percent format

Fixed 1 error:
- pymongo/operations.py:
    1 × SIM201 (negate-equal-op)

Found 3 errors (1 fixed, 2 remaining).

https://github.com/mongodb/mongo-python-driver/actions/runs/11335774791/job/31524560806?pr=1909#step:5:71

@aclark4life
Copy link
Contributor Author

Ruff wants you to use f-string or .format() instead:

ruff.....................................................................Failed
- hook id: ruff
- exit code: 1
- files were modified by this hook

pymongo/operations.py:777:16: UP031 Use format specifiers instead of percent format
pymongo/operations.py:782:21: UP031 Use format specifiers instead of percent format

Fixed 1 error:
- pymongo/operations.py:
    1 × SIM201 (negate-equal-op)

Found 3 errors (1 fixed, 2 remaining).

https://github.com/mongodb/mongo-python-driver/actions/runs/11335774791/job/31524560806?pr=1909#step:5:71

Fair enough, ruff 👍 ca34322

@aclark4life
Copy link
Contributor Author

Thanks @timgraham and @ShaneHarvey, I think this is ready to go

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.

LGTM besides some bikeshedding I won't speak definitively about.

@aclark4life
Copy link
Contributor Author

LGTM besides some bikeshedding I won't speak definitively about.

Thanks! May as well bikeshed while we are in here. I have implemented your suggestions as well as moved assertRepr to the base test class.

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a note in the doc/changelog.rst? Here's an example:

- Added :func:`repr` support to :class:`bson.tz_util.FixedOffset`.

@@ -773,6 +773,19 @@ def document(self) -> dict[str, Any]:
"""
return self.__document

def __repr__(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruff is still failing because it wants you to use f-strings. Do you have pre-commit set up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, forgot my pre-commit install! I think I just need to add a more meaningful test to the SearchIndexModel test class to finish this.

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid force pushing because it makes it harder to review what's changed on the new commits.

@ShaneHarvey ShaneHarvey changed the title PYTHON-4834 Add __repr__ to IndexModel PYTHON-4834 Add __repr__ to IndexModel, SearchIndexModel Oct 15, 2024
@aclark4life aclark4life merged commit 8034bae into mongodb:master Oct 15, 2024
25 of 26 checks passed
@aclark4life aclark4life deleted the PYTHON-4834 branch October 15, 2024 22:45
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.

3 participants