Skip to content

Commit 0e987fc

Browse files
WaVEVtimgraham
authored andcommitted
Amend errors messages
1 parent 80fffa5 commit 0e987fc

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

django_mongodb_backend/indexes.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ def check(self, model, connection):
114114
if not connection.features.supports_atlas_search:
115115
errors.append(
116116
Warning(
117-
"This MongoDB server does not support atlas search.",
117+
f"This MongoDB server does not support {self.__class__.__name__}.",
118118
hint=(
119-
"The index won't be created. Silence this warning if you "
120-
"don't care about it."
119+
"The index won't be created. Use an Atlas-enabled version of MongoDB, "
120+
"or silence this warning if you don't care about it."
121121
),
122-
obj=self,
122+
obj=model,
123123
id=f"{self._error_id_prefix}.W001",
124124
)
125125
)
@@ -198,7 +198,7 @@ def check(self, model, connection):
198198
errors.append(
199199
Error(
200200
f"Atlas vector search requires size on {field_name}.",
201-
obj=self,
201+
obj=model,
202202
id=f"{self._error_id_prefix}.E001",
203203
)
204204
)
@@ -209,7 +209,7 @@ def check(self, model, connection):
209209
"field of ArrayField Model.field_name "
210210
"to be FloatField or DecimalField but "
211211
f"is {field_.base_field.get_internal_type()}.",
212-
obj=self,
212+
obj=model,
213213
id=f"{self._error_id_prefix}.E002",
214214
)
215215
)
@@ -222,8 +222,9 @@ def check(self, model, connection):
222222
if search_type not in {"number", "string", "boolean", "objectId", "uuid", "date"}:
223223
errors.append(
224224
Error(
225-
f"Unsupported filter of type {field_.get_internal_type()}.",
226-
obj=self,
225+
"VectorSearchIndex does not support "
226+
f"'{field_.get_internal_type()}' {field_name}.",
227+
obj=model,
227228
id=f"{self._error_id_prefix}.E003",
228229
)
229230
)
@@ -238,8 +239,8 @@ def check(self, model, connection):
238239
f"{similarity_function_text} were expected and "
239240
f"{len(self.similarities)} {'were' if len(self.similarities) != 1 else 'was'} "
240241
"provided.",
241-
obj=self,
242-
id=f"{self._error_id_prefix}.E005",
242+
obj=model,
243+
id=f"{self._error_id_prefix}.E004",
243244
)
244245
)
245246
return errors

tests/indexes_/test_checks.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class Meta:
2727
errors,
2828
[
2929
checks.Warning(
30-
"This MongoDB server does not support atlas search.",
30+
"This MongoDB server does not support SearchIndex.",
3131
hint=(
32-
"The index won't be created. Silence this warning if you "
33-
"don't care about it."
32+
"The index won't be created. Use an Atlas-enabled version of MongoDB, "
33+
"or silence this warning if you don't care about it."
3434
),
35-
obj=Article._meta.indexes[0],
35+
obj=Article,
3636
id="django_mongodb_backend.indexes.SearchIndex.W001",
3737
)
3838
],
@@ -50,12 +50,12 @@ class Meta:
5050
errors,
5151
[
5252
checks.Warning(
53-
"This MongoDB server does not support atlas search.",
53+
"This MongoDB server does not support VectorSearchIndex.",
5454
hint=(
55-
"The index won't be created. Silence this warning if you "
56-
"don't care about it."
55+
"The index won't be created. Use an Atlas-enabled version of MongoDB, "
56+
"or silence this warning if you don't care about it."
5757
),
58-
obj=Article._meta.indexes[0],
58+
obj=Article,
5959
id="django_mongodb_backend.indexes.VectorSearchIndex.W001",
6060
)
6161
],
@@ -80,7 +80,7 @@ class Meta:
8080
checks.Error(
8181
"Atlas vector search requires size on title_embedded.",
8282
id="django_mongodb_backend.indexes.VectorSearchIndex.E001",
83-
obj=Article._meta.indexes[0],
83+
obj=Article,
8484
)
8585
],
8686
)
@@ -100,7 +100,7 @@ class Meta:
100100
"An Atlas vector search index requires the base field of ArrayField "
101101
"Model.field_name to be FloatField or DecimalField but is CharField.",
102102
id="django_mongodb_backend.indexes.VectorSearchIndex.E002",
103-
obj=Article._meta.indexes[0],
103+
obj=Article,
104104
)
105105
],
106106
)
@@ -119,9 +119,9 @@ class Meta:
119119
errors,
120120
[
121121
checks.Error(
122-
"Unsupported filter of type JSONField.",
122+
"VectorSearchIndex does not support 'JSONField' data.",
123123
id="django_mongodb_backend.indexes.VectorSearchIndex.E003",
124-
obj=Article._meta.indexes[0],
124+
obj=Article,
125125
)
126126
],
127127
)
@@ -146,8 +146,8 @@ class Meta:
146146
"An Atlas vector search index requires the same number of similarities "
147147
"and vector fields, but 1 similarity function were expected and 2 "
148148
"were provided.",
149-
id="django_mongodb_backend.indexes.VectorSearchIndex.E005",
150-
obj=Article._meta.indexes[0],
149+
id="django_mongodb_backend.indexes.VectorSearchIndex.E004",
150+
obj=Article,
151151
),
152152
],
153153
)
@@ -173,8 +173,8 @@ class Meta:
173173
"An Atlas vector search index requires the same number of similarities "
174174
"and vector fields, but 2 similarities functions were expected and 1 "
175175
"was provided.",
176-
id="django_mongodb_backend.indexes.VectorSearchIndex.E005",
177-
obj=Article._meta.indexes[0],
176+
id="django_mongodb_backend.indexes.VectorSearchIndex.E004",
177+
obj=Article,
178178
),
179179
],
180180
)

0 commit comments

Comments
 (0)