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

GridFS spec test can fail with UnboundLocalError: local variable 'result' referenced before assignment

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

       [2019/10/24 15:14:30.473] ERROR: test_download (test.test_gridfs_spec.TestAllScenarios)
       [2019/10/24 15:14:30.473] ----------------------------------------------------------------------
       [2019/10/24 15:14:30.473] Traceback (most recent call last):
       [2019/10/24 15:14:30.473]   File "/data/mci/6ba00614a2279a83cbe73498853dcce9/src/.tox/synchro37/tmp/mongo-python-driver/test/test_gridfs_spec.py", line 158, in run_scenario
       [2019/10/24 15:14:30.473]     self.init_expected_db(test, result)
       [2019/10/24 15:14:30.473] UnboundLocalError: local variable 'result' referenced before assignment
      

      The problem is that "result" is potentially undefined in this block:

                  error = None
                  try:
                      result = operation(**converted_args)
      
                      if 'download' in test['act']['operation']:
                          result = Binary(result.read())
                  except Exception as exc:
                      error = exc
      
                  self.init_expected_db(test, result)
      

      Noticed while working on MOTOR-228.

            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: