diff --git a/backend/sophon/notebooks/models.py b/backend/sophon/notebooks/models.py index 14fcb10..aafd99d 100644 --- a/backend/sophon/notebooks/models.py +++ b/backend/sophon/notebooks/models.py @@ -381,7 +381,10 @@ class Notebook(SophonGroupModel): if self.container_id is None: return None - return docker_client.containers.get(self.container_id) + try: + return docker_client.containers.get(self.container_id) + except docker.errors.NotFound: + return None def sync_container(self) -> t.Optional[docker.models.containers.Container]: """ diff --git a/backend/sophon/notebooks/views.py b/backend/sophon/notebooks/views.py index b945a3f..e09db94 100644 --- a/backend/sophon/notebooks/views.py +++ b/backend/sophon/notebooks/views.py @@ -31,7 +31,7 @@ class NotebooksViewSet(SophonGroupViewSet, metaclass=abc.ABCMeta): """ notebook: Notebook = self.get_object() notebook.sync_container() - Serializer = notebook.get_access_serializer(request.user) + Serializer = self.get_serializer_class() serializer = Serializer(notebook) return Response(serializer.data, status.HTTP_200_OK) @@ -42,7 +42,7 @@ class NotebooksViewSet(SophonGroupViewSet, metaclass=abc.ABCMeta): """ notebook: Notebook = self.get_object() notebook.start() - Serializer = notebook.get_access_serializer(request.user) + Serializer = self.get_serializer_class() serializer = Serializer(notebook) return Response(serializer.data, status.HTTP_200_OK) @@ -57,7 +57,7 @@ class NotebooksViewSet(SophonGroupViewSet, metaclass=abc.ABCMeta): if notebook.locked_by is None: notebook.locked_by = self.request.user notebook.save() - Serializer = notebook.get_access_serializer(request.user) + Serializer = self.get_serializer_class() serializer = Serializer(notebook) return Response(serializer.data, status.HTTP_200_OK) @@ -71,7 +71,7 @@ class NotebooksViewSet(SophonGroupViewSet, metaclass=abc.ABCMeta): notebook: Notebook = self.get_object() notebook.locked_by = None notebook.save() - Serializer = notebook.get_access_serializer(request.user) + Serializer = self.get_serializer_class() serializer = Serializer(notebook) return Response(serializer.data, status.HTTP_200_OK) @@ -82,7 +82,7 @@ class NotebooksViewSet(SophonGroupViewSet, metaclass=abc.ABCMeta): """ notebook: Notebook = self.get_object() notebook.stop() - Serializer = notebook.get_access_serializer(request.user) + Serializer = self.get_serializer_class() serializer = Serializer(notebook) return Response(serializer.data, status.HTTP_200_OK)