From 4f884898fb407be6e582db51d91fc0041be378b1 Mon Sep 17 00:00:00 2001 From: Alexander Saprykin Date: Fri, 13 Sep 2024 13:02:26 +0200 Subject: [PATCH] Fix SonarCloud code quality issues No-Issue --- galaxy_ng/app/api/v1/serializers.py | 11 ++++- galaxy_ng/app/api/v1/viewsets/tasks.py | 11 ++++- galaxy_ng/app/api/v3/serializers/__init__.py | 30 +++++++------ galaxy_ng/app/api/v3/viewsets/__init__.py | 46 +++++++++----------- 4 files changed, 57 insertions(+), 41 deletions(-) diff --git a/galaxy_ng/app/api/v1/serializers.py b/galaxy_ng/app/api/v1/serializers.py index 364604f757..6975edb288 100644 --- a/galaxy_ng/app/api/v1/serializers.py +++ b/galaxy_ng/app/api/v1/serializers.py @@ -756,7 +756,16 @@ def get_summary_fields(self, obj): for message in obj.messages: msg_type = self.MSG_TYPE_MAP.get(message['level'], message['level']) - ts = datetime.datetime.utcfromtimestamp(message['time']).isoformat() + # FIXME(cutwater): The `datetime.utcfromtimestamp` method used here is a cause of + # multiple problems (deprecated method, naive-datetime object result, + # SonarCloud reliability issue). It returned a naive datetime object, which + # should be avoided in general. The recommended fix is to build + # a timezone-aware datetime object: `datetime.fromtimestamp(ts, timezone.utc)`. + # However to preserve current behavior we will return a naive object for now + # and revisit this code in future. + ts = datetime.datetime.fromtimestamp( + message['time'], tz=datetime.timezone.utc + ).replace(tzinfo=None).isoformat() msg_state = self.STATE_MAP.get(message['state'].upper(), message['state'].upper()) msg = { 'id': ts, diff --git a/galaxy_ng/app/api/v1/viewsets/tasks.py b/galaxy_ng/app/api/v1/viewsets/tasks.py index 0735bd3f43..762d3dbcd1 100644 --- a/galaxy_ng/app/api/v1/viewsets/tasks.py +++ b/galaxy_ng/app/api/v1/viewsets/tasks.py @@ -93,7 +93,16 @@ def get_task(self, request, id=None): if roleimport: for message in roleimport.messages: msg_type = msg_type_map.get(message['level'], message['level']) - ts = datetime.datetime.utcfromtimestamp(message['time']).isoformat() + # FIXME(cutwater): The `datetime.utcfromtimestamp` method used here is a cause of + # multiple problems (deprecated method, naive-datetime object result, + # SonarCloud reliability issue). It returned a naive datetime object, which + # should be avoided in general. The recommended fix is to build + # a timezone-aware datetime object: `datetime.fromtimestamp(ts, timezone.utc)`. + # However to preserve current behavior we will return a naive object for now + # and revisit this code in future. + ts = datetime.datetime.fromtimestamp( + message['time'], tz=datetime.timezone.utc + ).replace(tzinfo=None).isoformat() msg_state = state_map.get(message['state'].upper(), message['state'].upper()) msg = { 'id': ts, diff --git a/galaxy_ng/app/api/v3/serializers/__init__.py b/galaxy_ng/app/api/v3/serializers/__init__.py index b06bbbacb8..9b0d83e854 100644 --- a/galaxy_ng/app/api/v3/serializers/__init__.py +++ b/galaxy_ng/app/api/v3/serializers/__init__.py @@ -26,17 +26,21 @@ ) __all__ = ( - 'CollectionUploadSerializer', - 'GroupSummarySerializer', - 'NamespaceSerializer', - 'NamespaceSummarySerializer', - 'TaskSerializer', - 'TaskSummarySerializer', - 'UnpaginatedCollectionVersionSerializer', - 'ContainerRepositorySerializer', - 'ContainerRepositoryHistorySerializer', - 'ContainerManifestSerializer', - 'ContainerTagSerializer', - 'ContainerManifestDetailSerializer', - 'ContainerReadmeSerializer', + # collection + "CollectionUploadSerializer", + # namespace + "NamespaceSerializer", + "NamespaceSummarySerializer", + # group + "GroupSummarySerializer", + # task + "TaskSerializer", + "TaskSummarySerializer", + # execution_environment + "ContainerRepositorySerializer", + "ContainerTagSerializer", + "ContainerManifestSerializer", + "ContainerManifestDetailSerializer", + "ContainerReadmeSerializer", + "ContainerRepositoryHistorySerializer", ) diff --git a/galaxy_ng/app/api/v3/viewsets/__init__.py b/galaxy_ng/app/api/v3/viewsets/__init__.py index ea2de5c18a..059488e4b8 100644 --- a/galaxy_ng/app/api/v3/viewsets/__init__.py +++ b/galaxy_ng/app/api/v3/viewsets/__init__.py @@ -4,39 +4,33 @@ CollectionVersionMoveViewSet, CollectionVersionCopyViewSet, ) - -from .namespace import ( - NamespaceViewSet, -) - -from .task import ( - TaskViewSet, -) - +from .namespace import NamespaceViewSet +from .task import TaskViewSet from .sync import SyncConfigViewSet - from .execution_environments import ( ContainerRepositoryViewSet, ContainerRepositoryManifestViewSet, ContainerRepositoryHistoryViewSet, ContainerReadmeViewSet, - ContainerTagViewset + ContainerTagViewset, ) __all__ = ( - 'CollectionArtifactDownloadView', - 'CollectionUploadViewSet', - 'CollectionVersionMoveViewSet', - 'CollectionVersionCopyViewSet', - 'NamespaceViewSet', - 'SyncConfigViewSet', - 'TaskViewSet', - 'UnpaginatedCollectionViewSet', - 'UnpaginatedCollectionVersionViewSet', - 'RepoMetadataViewSet', - 'ContainerRepositoryViewSet', - 'ContainerRepositoryManifestViewSet', - 'ContainerRepositoryHistoryViewSet', - 'ContainerReadmeViewSet', - 'ContainerTagViewset' + # collection + "CollectionArtifactDownloadView", + "CollectionUploadViewSet", + "CollectionVersionMoveViewSet", + "CollectionVersionCopyViewSet", + # namespace + "NamespaceViewSet", + # task + "TaskViewSet", + # sync + "SyncConfigViewSet", + # execution_environments + "ContainerRepositoryViewSet", + "ContainerRepositoryManifestViewSet", + "ContainerRepositoryHistoryViewSet", + "ContainerReadmeViewSet", + "ContainerTagViewset", )