Skip to content

Commit e223e8d

Browse files
committed
Close s3 connections
1 parent 357d617 commit e223e8d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

rnacentral/apiv1/views.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ def get(self, request, pk=None, format=None):
520520
s3_file = "prod/" + upi_path + self.kwargs["pk"] + ".svg.gz"
521521
s3_obj = s3.Object(settings.S3_SERVER["BUCKET"], s3_file)
522522
try:
523-
s3_svg = zlib.decompress(s3_obj.get()["Body"].read(), zlib.MAX_WBITS | 32)
523+
with s3_obj.get()["Body"] as s3_body:
524+
s3_svg = zlib.decompress(s3_body.read(), zlib.MAX_WBITS | 32)
524525
except s3.meta.client.exceptions.NoSuchKey:
525526
return Response(status=status.HTTP_404_NOT_FOUND)
526527

rnacentral/portal/models/rna.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import itertools as it
1515
import operator as op
16-
import re
1716
import zlib
1817
from collections import Counter, defaultdict
1918

@@ -606,8 +605,9 @@ def get_layout_secondary(self):
606605
s3_file = "prod/" + upi_path + self.pk + ".svg.gz"
607606
s3_obj = s3.Object(settings.S3_SERVER["BUCKET"], s3_file)
608607
try:
609-
svg = zlib.decompress(s3_obj.get()["Body"].read(), zlib.MAX_WBITS | 32)
610-
svg = svg.replace(b"rgb(255, 0, 0)", b"rgb(255,0,255)")
608+
with s3_obj.get()["Body"] as s3_body:
609+
svg = zlib.decompress(s3_body.read(), zlib.MAX_WBITS | 32)
610+
svg = svg.replace(b"rgb(255, 0, 0)", b"rgb(255,0,255)")
611611
except s3.meta.client.exceptions.NoSuchKey:
612612
svg = None
613613

0 commit comments

Comments
 (0)