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

ChangeStreamsWCustomTypesTestMixin fails with DuplicateKeyError

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.10
    • Affects Version/s: 3.9
    • Component/s: Tests
    • None

      The tests in test_custom_types.ChangeStreamsWCustomTypesTestMixin will fail if the underlying collection has existing data in it. The tests should clear the test collection before/after running. This ticket is blocking MOTOR-425.

      Repro:

      $ python3.7
      Python 3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52)
      [Clang 6.0 (clang-600.0.57)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> client.pymongo_test.test.insert_one({'_id': 1})
      <pymongo.results.InsertOneResult object at 0x102bec5f0>
      >>> ^D
      $ python3.7 setup.py test -s test.test_custom_types
      running test
      running egg_info
      writing pymongo.egg-info/PKG-INFO
      writing dependency_links to pymongo.egg-info/dependency_links.txt
      writing requirements to pymongo.egg-info/requires.txt
      writing top-level names to pymongo.egg-info/top_level.txt
      reading manifest file 'pymongo.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      writing manifest file 'pymongo.egg-info/SOURCES.txt'
      running build_ext
      test_chaining_encoders_fails (test.test_custom_types.TestBSONCustomTypeEncoderAndFallbackEncoderTandem) ... ok
      test_encode_custom_then_fallback (test.test_custom_types.TestBSONCustomTypeEncoderAndFallbackEncoderTandem) ... ok
      test_encode_fallback_then_custom (test.test_custom_types.TestBSONCustomTypeEncoderAndFallbackEncoderTandem) ... ok
      test_infinite_loop_exceeds_max_recursion_depth (test.test_custom_types.TestBSONCustomTypeEncoderAndFallbackEncoderTandem) ... ok
      test_erroring_fallback_encoder (test.test_custom_types.TestBSONFallbackEncoder) ... ok
      test_noop_fallback_encoder (test.test_custom_types.TestBSONFallbackEncoder) ... ok
      test_simple (test.test_custom_types.TestBSONFallbackEncoder) ... ok
      test_type_unencodable_by_fallback_encoder (test.test_custom_types.TestBSONFallbackEncoder) ... ok
      test_instantiation (test.test_custom_types.TestBSONTypeEnDeCodecs) ... ok
      test_type_checks (test.test_custom_types.TestBSONTypeEnDeCodecs) ... ok
      test_break_resume_token (test.test_custom_types.TestClusterChangeStreamsWCustomTypes) ... ERROR
      test_custom_type_in_pipeline (test.test_custom_types.TestClusterChangeStreamsWCustomTypes) ... ok
      test_document_class (test.test_custom_types.TestClusterChangeStreamsWCustomTypes) ... ok
      test_simple (test.test_custom_types.TestClusterChangeStreamsWCustomTypes) ... ok
      test_break_resume_token (test.test_custom_types.TestCollectionChangeStreamsWCustomTypes) ... ok
      test_custom_type_in_pipeline (test.test_custom_types.TestCollectionChangeStreamsWCustomTypes) ... ok
      test_document_class (test.test_custom_types.TestCollectionChangeStreamsWCustomTypes) ... ok
      test_simple (test.test_custom_types.TestCollectionChangeStreamsWCustomTypes) ... ok
      test_aggregate_w_custom_type_decoder (test.test_custom_types.TestCollectionWCustomType) ... ok
      test_command_errors_w_custom_type_decoder (test.test_custom_types.TestCollectionWCustomType) ... ok
      test_distinct_w_custom_type (test.test_custom_types.TestCollectionWCustomType) ... ok
      test_find_and_modify_w_custom_type_decoder (test.test_custom_types.TestCollectionWCustomType) ... ok
      test_find_one_and__w_custom_type_decoder (test.test_custom_types.TestCollectionWCustomType) ... ok
      test_find_w_custom_type_decoder (test.test_custom_types.TestCollectionWCustomType) ... ok
      test_find_w_custom_type_decoder_and_document_class (test.test_custom_types.TestCollectionWCustomType) ... ok
      test_group_w_custom_type (test.test_custom_types.TestCollectionWCustomType) ... skipped 'Server version must be at most 4.1.0.-1'
      test_map_reduce_w_custom_type (test.test_custom_types.TestCollectionWCustomType) ... ok
      test__bson_to_dict (test.test_custom_types.TestCustomPythonBSONTypeToBSONMonolithicCodec) ... ok
      test__dict_to_bson (test.test_custom_types.TestCustomPythonBSONTypeToBSONMonolithicCodec) ... ok
      test_decode_all (test.test_custom_types.TestCustomPythonBSONTypeToBSONMonolithicCodec) ... ok
      test_decode_file_iter (test.test_custom_types.TestCustomPythonBSONTypeToBSONMonolithicCodec) ... ok
      test_decode_iter (test.test_custom_types.TestCustomPythonBSONTypeToBSONMonolithicCodec) ... ok
      test_encode_decode_roundtrip (test.test_custom_types.TestCustomPythonBSONTypeToBSONMonolithicCodec) ... ok
      test__bson_to_dict (test.test_custom_types.TestCustomPythonBSONTypeToBSONMultiplexedCodec) ... ok
      test__dict_to_bson (test.test_custom_types.TestCustomPythonBSONTypeToBSONMultiplexedCodec) ... ok
      test_decode_all (test.test_custom_types.TestCustomPythonBSONTypeToBSONMultiplexedCodec) ... ok
      test_decode_file_iter (test.test_custom_types.TestCustomPythonBSONTypeToBSONMultiplexedCodec) ... ok
      test_decode_iter (test.test_custom_types.TestCustomPythonBSONTypeToBSONMultiplexedCodec) ... ok
      test_encode_decode_roundtrip (test.test_custom_types.TestCustomPythonBSONTypeToBSONMultiplexedCodec) ... ok
      test_break_resume_token (test.test_custom_types.TestDatabaseChangeStreamsWCustomTypes) ... ok
      test_custom_type_in_pipeline (test.test_custom_types.TestDatabaseChangeStreamsWCustomTypes) ... ok
      test_document_class (test.test_custom_types.TestDatabaseChangeStreamsWCustomTypes) ... ok
      test_simple (test.test_custom_types.TestDatabaseChangeStreamsWCustomTypes) ... ok
      test_grid_out_custom_opts (test.test_custom_types.TestGridFileCustomType) ... ok
      test_builtin_types_override_fails (test.test_custom_types.TestTypeRegistry) ... ok
      test_initialize_fail (test.test_custom_types.TestTypeRegistry) ... ok
      test_simple (test.test_custom_types.TestTypeRegistry) ... ok
      test_simple_separate_codecs (test.test_custom_types.TestTypeRegistry) ... ok
      test_type_registry_eq (test.test_custom_types.TestTypeRegistry) ... ok
      test_type_registry_repr (test.test_custom_types.TestTypeRegistry) ... ok
      
      ======================================================================
      ERROR: test_break_resume_token (test.test_custom_types.TestClusterChangeStreamsWCustomTypes)
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/Users/shane/git/mongo-python-driver/test/test_custom_types.py", line 823, in test_break_resume_token
          self.insert_and_check(change_stream, docs[0], docs[0])
        File "/Users/shane/git/mongo-python-driver/test/test_custom_types.py", line 748, in insert_and_check
          self.input_target.insert_one(insert_doc)
        File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 698, in insert_one
          session=session),
        File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 612, in _insert
          bypass_doc_val, session)
        File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 600, in _insert_one
          acknowledged, _insert_command, session)
        File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1492, in _retryable_write
          return self._retry_with_session(retryable, func, s, None)
        File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1385, in _retry_with_session
          return func(session, sock_info, retryable)
        File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 597, in _insert_command
          _check_write_command_response(result)
        File "/Users/shane/git/mongo-python-driver/pymongo/helpers.py", line 221, in _check_write_command_response
          _raise_last_write_error(write_errors)
        File "/Users/shane/git/mongo-python-driver/pymongo/helpers.py", line 202, in _raise_last_write_error
          raise DuplicateKeyError(error.get("errmsg"), 11000, error)
      pymongo.errors.DuplicateKeyError: E11000 duplicate key error collection: pymongo_test.test index: _id_ dup key: { _id: 1 }
      
      ----------------------------------------------------------------------
      Ran 50 tests in 2.316s
      
      FAILED (errors=1, skipped=1)
      

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: