diff --git a/warehouse/packaging/services.py b/warehouse/packaging/services.py index 264760cbeda6..fc49e512ec7c 100644 --- a/warehouse/packaging/services.py +++ b/warehouse/packaging/services.py @@ -11,6 +11,7 @@ # limitations under the License. import collections +import io import json import logging import os.path @@ -147,13 +148,17 @@ def _get_path(self, path): class GenericB2BlobStorage(GenericBlobStorage): def get(self, path): try: + file_obj = io.BytesIO() downloaded_file = self.bucket.download_file_by_name(path) + downloaded_file.save(file_obj) + file_obj.seek(0) + return file_obj except b2sdk.exception.FileNotPresent: raise FileNotFoundError(f"No such key: {path!r}") from None def get_metadata(self, path): try: - file_info = self.bucket.get_file_info_by_name(path) + return self.bucket.get_file_info_by_name(path).file_info except b2sdk.exception.FileNotPresent: raise FileNotFoundError(f"No such key: {path!r}") from None diff --git a/warehouse/packaging/tasks.py b/warehouse/packaging/tasks.py index 947fb31566b1..91911ab1845c 100644 --- a/warehouse/packaging/tasks.py +++ b/warehouse/packaging/tasks.py @@ -48,7 +48,11 @@ def sync_file_to_archive(request, file_id): def check_file_archive_tasks_outstanding(request): metrics = request.find_service(IMetricsService, context=None) - files_not_archived = request.db.query(File).filter(File.archived == False).count() + files_not_archived = ( + request.db.query(File) + .filter(File.archived == False) # noqa: E712 + .count() + ) metrics.gauge( "warehouse.packaging.files.not_archived",