OptionsMapper raises NoMethodError reverting serverMonitoringMode option

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: 2.24.1
    • Component/s: URI Options
    • None
    • None
    • Ruby Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Description

      Mongo::URI::OptionsMapper is missing a revert_server_monitoring_mode method, while the serverMonitoringMode URI option is registered with type: :server_monitoring_mode. When client options containing :server_monitoring_mode are reverted back to standardized MongoClient options, the mapper dispatches to a method that does not exist and raises NoMethodError.

      The dispatch happens in ruby_to_smc (lib/mongo/uri/options_mapper.rb):

      if type = spec[:type]
        v = send("revert_#{type}", v)
      end
      

      With type == :server_monitoring_mode, this calls revert_server_monitoring_mode(v). Only convert_server_monitoring_mode and stringify_server_monitoring_mode are defined for this type; the revert_ variant is absent, so the call fails with:

      NoMethodError: undefined method `revert_server_monitoring_mode'
      

      Every other option type (bool, integer, ms, symbol, auth_mech, etc.) defines a matching revert_* method. server_monitoring_mode is the only registered type that does not, which is why the gap went unnoticed.

      Impact

      Any code path that reverts client options to standardized MongoClient options (i.e. calls OptionsMapper#ruby_to_smc) fails when serverMonitoringMode is present. Reading or converting URI options is unaffected; only the reverse direction is broken. This is a latent bug: it is not currently exercised by the test suite, which is why it does not surface in CI.

      Steps to Reproduce

      1. Construct client options that include server_monitoring_mode.
      2. Invoke the revert path (e.g. Mongo::URI::OptionsMapper.new.ruby_to_smc(server_monitoring_mode: :poll)).
      3. Observe the NoMethodError.

      Proposed Fix

      Add a revert_server_monitoring_mode method to Mongo::URI::OptionsMapper that converts the symbol value back to its string form (mirroring the existing stringify_server_monitoring_mode). An alias may suffice:

      def revert_server_monitoring_mode(value)
        value.to_s
      end
      

      Acceptance Criteria

      • ruby_to_smc handles the serverMonitoringMode option without raising.
      • A regression test covers reverting server_monitoring_mode through the mapper.
      • No RuboCop offenses introduced.

      Notes

      Found during the RUBY-3814 dead-code audit while verifying the OptionsMapper send-based dispatch. Reported as a separate ticket because it is a functional defect, not dead code.

            Assignee:
            Unassigned
            Reporter:
            Jamis Buck
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: