harvard-lil / capstone

CAP database scripts.
MIT License
188 stars 44 forks source link

Wrap deletion in try-except #2171

Closed bensteinberg closed 1 year ago

bensteinberg commented 1 year ago

On a test run of fab export_reporters_to_s3 we see this error:

Traceback (most recent call last):
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/fabric/main.py", line 763, in main
    *args, **kwargs
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/fabric/tasks.py", line 427, in execute
    results['<local-only>'] = task.run(*args, **new_kwargs)
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/fabric/tasks.py", line 174, in run
    return self.wrapped(*args, **kwargs)
  File "/usr/local/share/capstone-prod/capstone/fabfile.py", line 469, in export_reporters_to_s3
    convert_s3.put_reporters_on_s3(redacted=True)
  File "/usr/local/share/capstone-prod/capstone/scripts/convert_s3.py", line 83, in put_reporters_on_s3
    bucket, redacted, result["id"]
  File "/usr/local/share/capstone-prod/capstone/scripts/convert_s3.py", line 160, in export_cases_to_s3
    for volume_metadata in results.get():
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/celery/result.py", line 697, in get
    on_interval=on_interval,
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/celery/result.py", line 815, in join_native
    on_message, on_interval):
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/celery/backends/asynchronous.py", line 142, in iter_native
    for _ in self._wait_for_pending(result, no_ack=no_ack, **kwargs):
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/celery/backends/asynchronous.py", line 255, in _wait_for_pending
    on_interval=on_interval):
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/celery/backends/asynchronous.py", line 56, in drain_events_until
    yield self.wait_for(p, wait, timeout=1)
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/celery/backends/asynchronous.py", line 65, in wait_for
    wait(timeout=timeout)
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/celery/backends/redis.py", line 129, in drain_events
    self.on_state_change(self._decode_result(message['data']), message)
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/celery/backends/base.py", line 305, in decode_result
    return self.meta_from_decoded(self.decode(payload))
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/celery/backends/base.py", line 301, in meta_from_decoded
    meta['result'] = self.exception_to_python(meta['result'])
  File "/home/capstone/capstone-prod/lib/python3.7/site-packages/celery/backends/base.py", line 276, in exception_to_python
    cls = getattr(sys.modules[exc_module], exc_type)
AttributeError: module 'botocore.errorfactory' has no attribute 'NoSuchKey'

This PR wraps what I think is the only unwrapped s3_client call in this script in a try-except, printing a notice in this particular case and re-raising an exception otherwise.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage has no change and project coverage change: -0.03% :warning:

Comparison is base (212cd27) 62.05% compared to head (ca0c218) 62.03%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #2171 +/- ## =========================================== - Coverage 62.05% 62.03% -0.03% =========================================== Files 107 107 Lines 11800 11805 +5 =========================================== Hits 7323 7323 - Misses 4477 4482 +5 ``` [see 1 file with indirect coverage changes](https://app.codecov.io/gh/harvard-lil/capstone/pull/2171/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=harvard-lil)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

bensteinberg commented 1 year ago

Note that there is no direct evidence in the traceback that the delete call is the source of the error.