Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1057

Connect option validator should use validate_boolean_or_string

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 3.2.2
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible

      Currently passing a MongoDB connection URI with the "connect" option causes an exception due to the option validator. The exception occurs even with the warn option set to True since TypeErrors are not caught.

      Since any value passed to the URI options are parsed as a string, when the "connect" option is validated with validate_boolean it cannot be valid since the value will always be a string.

      This should be fixed by changing the validator used for the "connect" option from validate_boolean to validate_boolean_or_string which is already present.

      Reproduce Steps (from IPython

      In [1]: from pymongo import MongoClient
      In [2]: cx = MongoClient('mongodb://localhost/?connect=true')
      
      TypeError: connect must be True or False
      
      In [3]: cx = MongoClient('mongodb://localhost/?connect=1')
      
      TypeError: connect must be True or False
      
      In [4]: cx = MongoClient('mongodb://localhost/?connect=False')
      
      TypeError: connect must be True or False
      

      If there is a reason that "connect" must be validated in this way, it would be helpful to add a comment for why "connect" is the only option with the strict boolean validator.

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            sm11963 Sam Miller
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: