@@ -1362,27 +1362,27 @@ def cluster_modifying?(new_options)
13621362 # The argument may contain a subset of options that the client will
13631363 # eventually have; this method validates each of the provided options
13641364 # but does not check for interactions between combinations of options.
1365- def validate_new_options! ( opts )
1366- return Options ::Redacted . new unless opts
1367-
1368- validate_read_concern! ( opts [ :read_concern ] )
1369- validate_server_api! ( opts [ :server_api ] )
1370- validate_max_min_pool_size! ( opts )
1371- validate_max_connecting! ( opts )
1372- validate_read! ( opts )
1373- validate_compressors! ( opts )
1374- validate_srv_max_hosts! ( opts )
1375-
1376- invalid_options = opts . keys . map ( &:to_sym ) - VALID_OPTIONS
1377- if invalid_options . any?
1378- log_warn ( "Unsupported client options: #{ invalid_options . join ( ', ' ) } . These will be ignored." )
1379- opts = opts . select { |key , | VALID_OPTIONS . include? ( key . to_sym ) }
1380- end
1381-
1382- Lint . validate_underscore_read_preference ( opts [ :read ] )
1383- Lint . validate_read_concern_option ( opts [ :read_concern ] )
1365+ def validate_new_options! ( options )
1366+ return Options ::Redacted . new unless options
1367+
1368+ Options ::Redacted . new ( options ) . tap do |opts |
1369+ validate_read_concern! ( opts [ :read_concern ] )
1370+ validate_server_api! ( opts [ :server_api ] )
1371+ validate_max_min_pool_size! ( opts )
1372+ validate_max_connecting! ( opts )
1373+ validate_read! ( opts )
1374+ validate_compressors! ( opts )
1375+ validate_srv_max_hosts! ( opts )
1376+
1377+ invalid_options = opts . keys . map ( &:to_sym ) - VALID_OPTIONS
1378+ if invalid_options . any?
1379+ log_warn ( "Unsupported client options: #{ invalid_options . join ( ', ' ) } . These will be ignored." )
1380+ opts . delete_if { |key , | !VALID_OPTIONS . include? ( key . to_sym ) }
1381+ end
13841382
1385- Options ::Redacted . new ( opts )
1383+ Lint . validate_underscore_read_preference ( opts [ :read ] )
1384+ Lint . validate_read_concern_option ( opts [ :read_concern ] )
1385+ end
13861386 end
13871387
13881388 # Validates all options after they are set on the client.
@@ -1645,7 +1645,11 @@ def validate_compressors!(opts)
16451645 validate_zstd_compression!
16461646 end
16471647
1648- opts [ :compressors ] = compressors unless compressors . empty?
1648+ if compressors . empty?
1649+ opts . delete ( :compressors )
1650+ else
1651+ opts [ :compressors ] = compressors
1652+ end
16491653 end
16501654
16511655 def validate_snappy_compression!
0 commit comments