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

Add __repr__ to write result classes

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.6
    • Affects Version/s: None
    • Component/s: None

      This makes it easier to debug write result classes. For example, some retryable writes test was failing with:

      Traceback (most recent call last):
        File "/Users/shane/git/mongo-python-driver/test/test_retryable_writes.py", line 126, in run_scenario
          "%r != %r" % (expected_result, result))
      AssertionError: False is not true : {'deletedCount': 1, 'upsertedIds': {'3': 4}, 'upsertedCount': 1, 'insertedIds': {'4': 5, '2': 3, '0': 2}, 'matchedCount': 2, 'modifiedCount': 2} != <pymongo.results.BulkWriteResult object at 0x1037e5bc8>
      

      Once we add _repr_ to the write result classes we can get:

      Traceback (most recent call last):
        File "/Users/shane/git/mongo-python-driver/test/test_retryable_writes.py", line 126, in run_scenario
          "%r != %r" % (expected_result, result))
      AssertionError: False is not true : {'upsertedIds': {'3': 4}, 'deletedCount': 1, 'insertedIds': {'2': 3, '4': 5, '0': 2}, 'modifiedCount': 2, 'upsertedCount': 1, 'matchedCount': 2} != BulkWriteResult({'nMatched': 2, 'nInserted': 3, 'nModified': 2, 'upserted': [{'_id': 4, 'index': 3}], 'writeErrors': [], 'nUpserted': 1, 'writeConcernErrors': [], 'nRemoved': 1}, True)
      

      Which is much more informative.

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

              Created:
              Updated:
              Resolved: