Skip to content

Commit 05766b4

Browse files
committed
edits
1 parent 351905c commit 05766b4

File tree

4 files changed

+12
-53
lines changed

4 files changed

+12
-53
lines changed

django_mongodb_backend/features.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,10 @@ def supports_atlas_search(self):
558558
# the operation will not error when unsupported.
559559
self.connection.get_collection("django_migrations").list_search_indexes()
560560
except OperationFailure:
561-
# It would be best to check the error message or error code to, but
562-
# they vary across MongoDB versions. Example: "$listSearchIndexes
563-
# stage is only allowed on MongoDB Atlas".
561+
# It would be best to check the error message or error code to
562+
# avoid hiding some other exception, but the message/code varies
563+
# across MongoDB versions. Example error message:
564+
# "$listSearchIndexes stage is only allowed on MongoDB Atlas".
564565
return False
565566
else:
566567
return True

docs/source/ref/models/indexes.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ Model index reference
55
.. module:: django_mongodb_backend.indexes
66
:synopsis: Database indexes for MongoDB.
77

8-
Some MongoDB-specific indexes are available in
9-
``django_mongodb_backend.indexes``.
8+
Some MongoDB-specific :doc:`indexes <django:ref/models/indexes>`, for use on a
9+
model's :attr:`Meta.indexes <django.db.models.Options.indexes>` option, are
10+
available in ``django_mongodb_backend.indexes``.
1011

1112
``SearchIndex``
1213
===============

docs/source/releases/5.2.x.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ New features
1818

1919
*These features won't appear in Django MongoDB Backend 5.1.x.*
2020

21-
- Added :class:`.SearchIndex` and :class:`.VectorSearchIndex` for using on
22-
a model's ``Meta.indexes``.
21+
- Added :class:`.SearchIndex` and :class:`.VectorSearchIndex` for use on
22+
a model's :attr:`Meta.indexes <django.db.models.Options.indexes>`.
2323

2424
Backwards incompatible changes
2525
------------------------------

tests/indexes_/test_search_indexes.py

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_no_init_args(self):
4848
SearchIndex("foo")
4949

5050
def test_no_extra_kargs(self):
51-
"""Unused wargs that appear on Index aren't accepted."""
51+
"""Unused kwargs that appear on Index aren't accepted."""
5252
msg = "SearchIndex.__init__() got an unexpected keyword argument 'condition'"
5353
with self.assertRaisesMessage(TypeError, msg):
5454
SearchIndex(condition="")
@@ -62,12 +62,12 @@ def test_no_init_args(self):
6262
VectorSearchIndex("foo")
6363

6464
def test_no_extra_kargs(self):
65-
"""Unused wargs that appear on Index aren't accepted."""
65+
"""Unused kwargs that appear on Index aren't accepted."""
6666
msg = "VectorSearchIndex.__init__() got an unexpected keyword argument 'condition'"
6767
with self.assertRaisesMessage(TypeError, msg):
6868
VectorSearchIndex(condition="")
6969

70-
def test_no_similarities(self):
70+
def test_similarities_required(self):
7171
msg = (
7272
"VectorSearchIndex.__init__() missing 1 required keyword-only argument: 'similarities'"
7373
)
@@ -248,49 +248,6 @@ def test_multiple_fields(self):
248248
with connection.schema_editor() as editor:
249249
editor.remove_index(index=index, model=SearchIndexTestModel)
250250

251-
def test_similarities_value(self):
252-
index = VectorSearchIndex(
253-
name="recent_test_idx",
254-
fields=["vector_float", "vector_integer"],
255-
similarities="euclidean",
256-
)
257-
with connection.schema_editor() as editor:
258-
editor.add_index(index=index, model=SearchIndexTestModel)
259-
try:
260-
index_info = connection.introspection.get_constraints(
261-
cursor=None,
262-
table_name=SearchIndexTestModel._meta.db_table,
263-
)
264-
expected_options = {
265-
"latestDefinition": {
266-
"fields": [
267-
{
268-
"numDimensions": 10,
269-
"path": "vector_float",
270-
"similarity": "euclidean",
271-
"type": "vector",
272-
},
273-
{
274-
"numDimensions": 10,
275-
"path": "vector_integer",
276-
"similarity": "euclidean",
277-
"type": "vector",
278-
},
279-
]
280-
},
281-
"latestVersion": 0,
282-
"name": "recent_test_idx",
283-
"queryable": False,
284-
"type": "vectorSearch",
285-
}
286-
self.assertCountEqual(index_info[index.name]["columns"], index.fields)
287-
index_info[index.name]["options"].pop("id")
288-
index_info[index.name]["options"].pop("status")
289-
self.assertEqual(index_info[index.name]["options"], expected_options)
290-
finally:
291-
with connection.schema_editor() as editor:
292-
editor.remove_index(index=index, model=SearchIndexTestModel)
293-
294251
def test_similarities_list(self):
295252
index = VectorSearchIndex(
296253
name="recent_test_idx",

0 commit comments

Comments
 (0)