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

DBRef validation error when parsing object with "$ref" in a result set

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.13
    • Component/s: None
    • None
    • Python Drivers
    • 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?

      We're working on PM-3120, the server backport of query stats. The $queryStats aggregation stage returns query "shapes" from user queries with literals and field paths transformed but keywords retained.

      While backporting the server's v6.0, we ran into an issue on PyMongo version 3.13.0. We have a query that gets returned as a result document of $queryStats after being transformed to the following:

      {links: {$elemMatch: {$and: [{$ref: {$eq: "?object"}}, {$id: {$eq: "?object"}}]}}}

      The driver attempts to create a DBRef object out of the $ref object but fails with "collection must be an instance of str."

      We've run successfully the same test with PyMongo version 4.3.3. Looking at the source code (bson package, _init_.py / dbref.py files), it seems that a change was made between the two versions to do some extra validation before creating a DBRef object that ends up filtering out this invalid case (i.e. not treating it as a DBRef at all). 

      Is there a backport process of some kind to resolve the error on the earlier version?

      (Also, I can attach more diagnostic info if needed. This is reproducible on our backport branch.)

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            alyssa.clark@mongodb.com Alyssa Clark
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: