From f4e0fdccb85896e14ba77e4c30d283614d35b62f Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 20 Oct 2021 23:09:31 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20the=20serializer=20used=20?= =?UTF-8?q?by=20notebook=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/sophon/notebooks/models.py | 5 ++++- backend/sophon/notebooks/views.py | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) 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)