Skip to content

Commit c154c6b

Browse files
authored
PYTHON-4037 Avoid Appending Write/Read Concern in Atlas Search Index Helper Commands (#1570)
1 parent 44e4730 commit c154c6b

File tree

6 files changed

+297
-141
lines changed

6 files changed

+297
-141
lines changed

doc/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ PyMongo 4.7 brings a number of improvements including:
4141
:attr:`pymongo.monitoring.ConnectionReadyEvent.duration` properties.
4242
- Added the ``type`` and ``kwargs`` arguments to :class:`~pymongo.operations.SearchIndexModel` to enable
4343
creating vector search indexes in MongoDB Atlas.
44+
- Fixed a bug where ``read_concern`` and ``write_concern`` were improperly added to
45+
:meth:`~pymongo.collection.Collection.list_search_indexes` queries.
4446

4547

4648
Unavoidable breaking changes

pymongo/collection.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
_IndexList,
7373
_Op,
7474
)
75+
from pymongo.read_concern import DEFAULT_READ_CONCERN, ReadConcern
7576
from pymongo.read_preferences import ReadPreference, _ServerMode
7677
from pymongo.results import (
7778
BulkWriteResult,
@@ -81,7 +82,7 @@
8182
UpdateResult,
8283
)
8384
from pymongo.typings import _CollationIn, _DocumentType, _DocumentTypeArg, _Pipeline
84-
from pymongo.write_concern import WriteConcern, validate_boolean
85+
from pymongo.write_concern import DEFAULT_WRITE_CONCERN, WriteConcern, validate_boolean
8586

8687
T = TypeVar("T")
8788

@@ -119,7 +120,6 @@ class ReturnDocument:
119120
from pymongo.collation import Collation
120121
from pymongo.database import Database
121122
from pymongo.pool import Connection
122-
from pymongo.read_concern import ReadConcern
123123
from pymongo.server import Server
124124

125125

@@ -2364,7 +2364,10 @@ def list_search_indexes(
23642364
pipeline = [{"$listSearchIndexes": {"name": name}}]
23652365

23662366
coll = self.with_options(
2367-
codec_options=DEFAULT_CODEC_OPTIONS, read_preference=ReadPreference.PRIMARY
2367+
codec_options=DEFAULT_CODEC_OPTIONS,
2368+
read_preference=ReadPreference.PRIMARY,
2369+
write_concern=DEFAULT_WRITE_CONCERN,
2370+
read_concern=DEFAULT_READ_CONCERN,
23682371
)
23692372
cmd = _CollectionAggregationCommand(
23702373
coll,

test/index_management/createSearchIndex.json

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
"mappings": {
5151
"dynamic": true
5252
}
53-
},
54-
"type": "search"
53+
}
5554
}
5655
},
5756
"expectError": {
@@ -74,8 +73,7 @@
7473
"mappings": {
7574
"dynamic": true
7675
}
77-
},
78-
"type": "search"
76+
}
7977
}
8078
],
8179
"$db": "database0"
@@ -99,8 +97,7 @@
9997
"dynamic": true
10098
}
10199
},
102-
"name": "test index",
103-
"type": "search"
100+
"name": "test index"
104101
}
105102
},
106103
"expectError": {
@@ -124,68 +121,7 @@
124121
"dynamic": true
125122
}
126123
},
127-
"name": "test index",
128-
"type": "search"
129-
}
130-
],
131-
"$db": "database0"
132-
}
133-
}
134-
}
135-
]
136-
}
137-
]
138-
},
139-
{
140-
"description": "create a vector search index",
141-
"operations": [
142-
{
143-
"name": "createSearchIndex",
144-
"object": "collection0",
145-
"arguments": {
146-
"model": {
147-
"definition": {
148-
"fields": [
149-
{
150-
"type": "vector",
151-
"path": "plot_embedding",
152-
"numDimensions": 1536,
153-
"similarity": "euclidean"
154-
}
155-
]
156-
},
157-
"name": "test index",
158-
"type": "vectorSearch"
159-
}
160-
},
161-
"expectError": {
162-
"isError": true,
163-
"errorContains": "Atlas"
164-
}
165-
}
166-
],
167-
"expectEvents": [
168-
{
169-
"client": "client0",
170-
"events": [
171-
{
172-
"commandStartedEvent": {
173-
"command": {
174-
"createSearchIndexes": "collection0",
175-
"indexes": [
176-
{
177-
"definition": {
178-
"fields": [
179-
{
180-
"type": "vector",
181-
"path": "plot_embedding",
182-
"numDimensions": 1536,
183-
"similarity": "euclidean"
184-
}
185-
]
186-
},
187-
"name": "test index",
188-
"type": "vectorSearch"
124+
"name": "test index"
189125
}
190126
],
191127
"$db": "database0"

test/index_management/createSearchIndexes.json

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@
8383
"mappings": {
8484
"dynamic": true
8585
}
86-
},
87-
"type": "search"
86+
}
8887
}
8988
]
9089
},
@@ -108,8 +107,7 @@
108107
"mappings": {
109108
"dynamic": true
110109
}
111-
},
112-
"type": "search"
110+
}
113111
}
114112
],
115113
"$db": "database0"
@@ -134,8 +132,7 @@
134132
"dynamic": true
135133
}
136134
},
137-
"name": "test index",
138-
"type": "search"
135+
"name": "test index"
139136
}
140137
]
141138
},
@@ -160,70 +157,7 @@
160157
"dynamic": true
161158
}
162159
},
163-
"name": "test index",
164-
"type": "search"
165-
}
166-
],
167-
"$db": "database0"
168-
}
169-
}
170-
}
171-
]
172-
}
173-
]
174-
},
175-
{
176-
"description": "create a vector search index",
177-
"operations": [
178-
{
179-
"name": "createSearchIndexes",
180-
"object": "collection0",
181-
"arguments": {
182-
"models": [
183-
{
184-
"definition": {
185-
"fields": [
186-
{
187-
"type": "vector",
188-
"path": "plot_embedding",
189-
"numDimensions": 1536,
190-
"similarity": "euclidean"
191-
}
192-
]
193-
},
194-
"name": "test index",
195-
"type": "vectorSearch"
196-
}
197-
]
198-
},
199-
"expectError": {
200-
"isError": true,
201-
"errorContains": "Atlas"
202-
}
203-
}
204-
],
205-
"expectEvents": [
206-
{
207-
"client": "client0",
208-
"events": [
209-
{
210-
"commandStartedEvent": {
211-
"command": {
212-
"createSearchIndexes": "collection0",
213-
"indexes": [
214-
{
215-
"definition": {
216-
"fields": [
217-
{
218-
"type": "vector",
219-
"path": "plot_embedding",
220-
"numDimensions": 1536,
221-
"similarity": "euclidean"
222-
}
223-
]
224-
},
225-
"name": "test index",
226-
"type": "vectorSearch"
160+
"name": "test index"
227161
}
228162
],
229163
"$db": "database0"

0 commit comments

Comments
 (0)