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

URI Parser fails when some options have invalid values

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.9
    • None
    • None

    Description

      As per the connection string spec:

      Any invalid Values for a given key MUST be ignored and MUST log a WARN level message.
      

      However, invalid values for some URI options actually results in an error. For example:

      MongoClient("mongodb://example.com/?compressors=zlib&zlibCompressionLevel=invalid")
      

      results in:

      Traceback (most recent call last):
        File "/Users/pmital/Developer/mongo-python-driver/pymongo/compression_support.py", line 59, in validate_zlib_compression_level
          level = int(value)
      ValueError: invalid literal for int() with base 10: 'invalid'
       
      During handling of the above exception, another exception occurred:
       
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/Users/pmital/Developer/mongo-python-driver/pymongo/mongo_client.py", line 514, in __init__
          res = uri_parser.parse_uri(entity, port, warn=True)
        File "/Users/pmital/Developer/mongo-python-driver/pymongo/uri_parser.py", line 405, in parse_uri
          options.update(split_options(opts, validate, warn))
        File "/Users/pmital/Developer/mongo-python-driver/pymongo/uri_parser.py", line 201, in split_options
          return validate_options(options, warn)
        File "/Users/pmital/Developer/mongo-python-driver/pymongo/uri_parser.py", line 145, in validate_options
          return get_validated_options(opts, warn)
        File "/Users/pmital/Developer/mongo-python-driver/pymongo/common.py", line 645, in get_validated_options
          value = validator(opt, value)
        File "/Users/pmital/Developer/mongo-python-driver/pymongo/compression_support.py", line 61, in validate_zlib_compression_level
          raise TypeError("%s must be an integer, not %r." % (option, value))
      TypeError: zlibCompressionLevel must be an integer, not 'invalid'.
      

      This occurs due to the fact that we only catch ValueError and ConfigurationError in the validation of URI options. See the relevant code here.

      Attachments

        Issue Links

          Activity

            People

              prashant.mital Prashant Mital (Inactive)
              prashant.mital Prashant Mital (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: