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

Do not rely on namedtuple._asdict()

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.12, 3.11.2
    • Affects Version/s: None
    • Component/s: None
    • None

      The test suite fails on 3.4.2:

       [2020/11/20 22:33:48.824] FAIL: test_metadata (test_client.ClientUnitTest)
       [2020/11/20 22:33:48.824] ----------------------------------------------------------------------
       [2020/11/20 22:33:48.824] Traceback (most recent call last):
       [2020/11/20 22:33:48.824]   File "/data/mci/52b9e171edeb47e2aab844bb34d76fc9/src/test/test_client.py", line 296, in test_metadata
       [2020/11/20 22:33:48.824]     self.assertRaises(TypeError, DriverInfo, 'Foo', 1, 'a')
       [2020/11/20 22:33:48.824] AssertionError: TypeError not raised by DriverInfo
       [2020/11/20 22:33:48.824] ======================================================================
       [2020/11/20 22:33:48.824] FAIL: test_grid_out_custom_opts (test_custom_types.TestGridFileCustomType)
       [2020/11/20 22:33:48.824] ----------------------------------------------------------------------
       [2020/11/20 22:33:48.824] Traceback (most recent call last):
       [2020/11/20 22:33:48.824]   File "/data/mci/52b9e171edeb47e2aab844bb34d76fc9/src/test/test_custom_types.py", line 736, in test_grid_out_custom_opts
       [2020/11/20 22:33:48.824]     self.assertEqual({"foo": 'red', "bar": 'blue'}, two.metadata)
       [2020/11/20 22:33:48.824] AssertionError: {'foo': 'red', 'bar': 'blue'} != RawBSONDocument(b' \x00\x00\x00\x02foo\x0[333 chars]ne)))
       [2020/11/20 22:33:48.824] ======================================================================
       [2020/11/20 22:33:48.824] FAIL: test_grid_out_cursor_options (test_grid_file.TestGridFile)
       [2020/11/20 22:33:48.824] ----------------------------------------------------------------------
       [2020/11/20 22:33:48.824] Traceback (most recent call last):
       [2020/11/20 22:33:48.824]   File "/data/mci/52b9e171edeb47e2aab844bb34d76fc9/src/test/test_grid_file.py", line 242, in test_grid_out_cursor_options
       [2020/11/20 22:33:48.824]     self.assertEqual(cursor_dict, cursor_clone_dict)
       [2020/11/20 22:33:48.824] AssertionError: {'_Cu[35 chars]sor__exhaust_mgr': None, '_Cursor__max_await_t[1464 chars]': 0} != {'_Cu[35 chars]sor__data': deque([]), '_Cursor__hint': None, [1469 chars]None}
       [2020/11/20 22:33:48.824] Diff is 2289 characters long. Set self.maxDiff to None to see it.
       [2020/11/20 22:33:48.824] ======================================================================
       [2020/11/20 22:33:48.824] FAIL: test_json_options_with_options (test_json_util.TestJsonUtil)
       [2020/11/20 22:33:48.824] ----------------------------------------------------------------------
       [2020/11/20 22:33:48.824] Traceback (most recent call last):
       [2020/11/20 22:33:48.824]   File "/data/mci/52b9e171edeb47e2aab844bb34d76fc9/src/test/test_json_util.py", line 80, in test_json_options_with_options
       [2020/11/20 22:33:48.824]     opts3.uuid_representation, UuidRepresentation.JAVA_LEGACY)
       [2020/11/20 22:33:48.824] AssertionError: 3 != 5
      

      These failures are caused by this python bug in _asdict fixed in 3.4.4 (and possibly some early 3.5/3.6 releases):
      https://bugs.python.org/issue24931

      $ git grep _asdict | tee
      bson/codec_options.py:313:        opts = self._asdict()
      bson/json_util.py:327:        opts = self._asdict()
      pymongo/driver_info.py:33:        for name, value in self._asdict().items():
      

      We should either stop using _asdict or define it on these classes ourselves:

          def _asdict(self):
              return collections.OrderedDict(zip(self._fields, self))
      

            Assignee:
            prashant.mital Prashant Mital (Inactive)
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: