Skip to content

Commit

Permalink
Fix GMN getChecksum
Browse files Browse the repository at this point in the history
Requests no longer returns a context manager for response streams.
  • Loading branch information
rogerdahl committed Jun 27, 2023
1 parent b7d36e6 commit 2716f24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions gmn/src/d1_gmn/app/views/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ def get_checksum(request, pid):
)

sciobj_model = d1_gmn.app.models.ScienceObject.objects.get(pid__did=pid)
with _get_sciobj_iter(sciobj_model) as sciobj_iter:
checksum_obj = d1_common.checksum.create_checksum_object_from_iterator(
sciobj_iter, algorithm
)
sciobj_iter = _get_sciobj_iter(sciobj_model)
checksum_obj = d1_common.checksum.create_checksum_object_from_iterator(
sciobj_iter, algorithm
)
# Log the access of this object.
# TODO: look into log type other than 'read'
d1_gmn.app.event_log.log_read_event(pid, request)
Expand Down
8 changes: 6 additions & 2 deletions lib_common/src/d1_common/iter/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def __enter__(self):
return self

def __exit__(self, type, value, traceback):
if hasattr(self._stream, "close"):
self._stream.close()
self.close()

def __iter__(self):
"""Returns: Chunks of ``read()`` on stream.
Expand All @@ -59,6 +58,7 @@ def __iter__(self):
while True:
chunk_str = self._stream.read(self._chunk_size)
if not chunk_str:
self.close()
break
yield chunk_str

Expand All @@ -78,3 +78,7 @@ def size(self):
size = self._stream.seek(0, os.SEEK_END)
self._stream.seek(cur_pos)
return size

def close(self):
if hasattr(self._stream, "close"):
self._stream.close()

0 comments on commit 2716f24

Please sign in to comment.