File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -208,7 +208,12 @@ def create_collection_indexes(
208208 # Duplicate key for unique indexes are generally caused by invalid documents in the collection
209209 # such as multiple documents not having a value for the attribute used for the index
210210 # Log the error so it can be diagnosed and fixed
211- logger .exception (err )
211+ logger .error (
212+ "Duplicate key error for index '%s' on collection '%s': %s" ,
213+ index_details .name ,
214+ collection .name ,
215+ err ,
216+ )
212217
213218 if not ignore_duplicate_keys :
214219 raise
@@ -219,8 +224,25 @@ def create_collection_indexes(
219224
220225 # by default, drop the old index with old configuration and
221226 # create the index again with the new configuration.
222- collection .drop_index (index_details .name )
223- collection .create_index (keys , ** kwargs )
227+ logger .warning (
228+ "Index '%s' on collection '%s' definition (keys/options) has changed, dropping and recreating it." ,
229+ index_details .name ,
230+ collection .name ,
231+ )
232+ try :
233+ collection .drop_index (index_details .name )
234+ collection .create_index (keys , ** kwargs )
235+ except OperationFailure as recreate_err :
236+ logger .exception (
237+ "Failed to recreate index '%s' on collection '%s': %s. "
238+ "Please create it manually with: keys=%s, options=%s" ,
239+ index_details .name ,
240+ collection .name ,
241+ recreate_err ,
242+ keys ,
243+ kwargs ,
244+ )
245+ raise
224246 else :
225247 raise
226248
You can’t perform that action at this time.
0 commit comments