File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -214,10 +214,15 @@ def test_create_collection(self):
214
214
db = client .pymongo_test
215
215
coll = db .test_create_collection
216
216
self .addCleanup (coll .drop )
217
- with client .start_session () as s , s .start_transaction ():
218
- coll2 = db .create_collection (coll .name , session = s )
217
+
218
+ # Use with_transaction to avoid StaleConfig errors on sharded clusters.
219
+ def create_and_insert (session ):
220
+ coll2 = db .create_collection (coll .name , session = session )
219
221
self .assertEqual (coll , coll2 )
220
- coll .insert_one ({}, session = s )
222
+ coll .insert_one ({}, session = session )
223
+
224
+ with client .start_session () as s :
225
+ s .with_transaction (create_and_insert )
221
226
222
227
# Outside a transaction we raise CollectionInvalid on existing colls.
223
228
with self .assertRaises (CollectionInvalid ):
You can’t perform that action at this time.
0 commit comments