Skip to content

Commit 5ea6a17

Browse files
p-mongop
authored andcommitted
Fix RUBY-1876 cannot disable retryable reads/writes via URI options (mongodb#1436)
1 parent f8e6929 commit 5ea6a17

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

lib/mongo/client.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,25 @@ def initialize(addresses_or_uri, options = nil)
346346
else
347347
options = {}
348348
end
349-
unless options[:retry_reads] == false
350-
options[:retry_reads] = true
351-
end
352-
unless options[:retry_writes] == false
353-
options[:retry_writes] = true
354-
end
349+
355350
Lint.validate_underscore_read_preference(options[:read])
356351
Lint.validate_read_concern_option(options[:read_concern])
352+
357353
if addresses_or_uri.is_a?(::String)
358354
uri = URI.get(addresses_or_uri, options)
359355
addresses = uri.servers
360356
options = uri.client_options.merge(options)
361357
else
362358
addresses = addresses_or_uri
363359
end
360+
361+
unless options[:retry_reads] == false
362+
options[:retry_reads] = true
363+
end
364+
unless options[:retry_writes] == false
365+
options[:retry_writes] = true
366+
end
367+
364368
# Special handling for sdam_proc as it is only used during client
365369
# construction
366370
sdam_proc = options.delete(:sdam_proc)

spec/mongo/client_construction_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,52 @@
742742
end
743743
end
744744
end
745+
746+
context 'when retryReads URI option is given' do
747+
748+
context 'it is false' do
749+
let!(:uri) do
750+
'mongodb://127.0.0.1:27017/testdb?retryReads=false'
751+
end
752+
753+
it 'sets the option on the client' do
754+
expect(client.options[:retry_reads]).to be false
755+
end
756+
end
757+
758+
context 'it is true' do
759+
let!(:uri) do
760+
'mongodb://127.0.0.1:27017/testdb?retryReads=true'
761+
end
762+
763+
it 'sets the option on the client' do
764+
expect(client.options[:retry_reads]).to be true
765+
end
766+
end
767+
end
768+
769+
context 'when retryWrites URI option is given' do
770+
771+
context 'it is false' do
772+
let!(:uri) do
773+
'mongodb://127.0.0.1:27017/testdb?retryWrites=false'
774+
end
775+
776+
it 'sets the option on the client' do
777+
expect(client.options[:retry_writes]).to be false
778+
end
779+
end
780+
781+
context 'it is true' do
782+
let!(:uri) do
783+
'mongodb://127.0.0.1:27017/testdb?retryWrites=true'
784+
end
785+
786+
it 'sets the option on the client' do
787+
expect(client.options[:retry_writes]).to be true
788+
end
789+
end
790+
end
745791
end
746792

747793
context 'when options are provided not in the string' do

0 commit comments

Comments
 (0)