Make parse_uri() return "options" as a dict rather than _CaseInsensitiveDictionary

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor - P4
    • 4.14
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Detailed steps to reproduce the problem

      >>> from pymongo.uri_parser import parse_uri
      >>> parse_uri("mongodb://cluster0.example.mongodb.net/myDatabase?retryWrites=true&retryReads=true").get("options")
      Unknown macro: \{'retryWrites'}
      >>> type(parse_uri("mongodb://cluster0.example.mongodb.net/myDatabase?retryWrites=true&retryReads=true").get("options"))
      <class 'pymongo.common._CaseInsensitiveDictionary'>
      

      It led to a surprising behavior (unexpected lowercased options) when merging the options with another dictionary:

      >>> options = {'authSource': 'auth', 'retryWrites': True}
      >>> opts = parse_uri("mongodb://cluster0.example.mongodb.net/myDatabase?retryWrites=true&retryReads=true").get("options")
      {'retryWrites': True, 'retryReads': True}
      (Pdb) {**options, **opts}
      {'authSource': 'auth', 'retryWrites': True, 'retrywrites': True, 'retryreads': True}
      (Pdb) type(opts)
      <class 'pymongo.common._CaseInsensitiveDictionary'>
      (Pdb) type(options)
      <class 'dict'>
      

      Shane said, "I always hated _CaseInsensitiveDictionary. It's probably a bug that we return it to the user. It's supposed to be private."

      Definition of done: what must be done to consider the task complete?

      parse_uri("...").get("options")

       returns a plain dictionary.

      The exact Python version used, with patch level:

      3.12.3

      The exact version of PyMongo used, with patch level:

      4.13.2

              Assignee:
              Iris Ho
              Reporter:
              Tim Graham
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: