Skip to content

Commit

Permalink
Fix SonarCloud code quality issues (#2263)
Browse files Browse the repository at this point in the history
No-Issue
  • Loading branch information
cutwater authored Sep 17, 2024
1 parent 8ab50e7 commit 44b6ccf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 41 deletions.
11 changes: 10 additions & 1 deletion galaxy_ng/app/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion galaxy_ng/app/api/v1/viewsets/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 17 additions & 13 deletions galaxy_ng/app/api/v3/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
46 changes: 20 additions & 26 deletions galaxy_ng/app/api/v3/viewsets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

0 comments on commit 44b6ccf

Please sign in to comment.