From 268d583eb5ec235d5acaa5ca73a08660b64d94e5 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 20 Dec 2021 14:54:09 +0900 Subject: [PATCH] Fix errors property in Writer It needs to return serializable object. --- backend/api/views/upload/writers.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/api/views/upload/writers.py b/backend/api/views/upload/writers.py index 9e6eab8c..5b662353 100644 --- a/backend/api/views/upload/writers.py +++ b/backend/api/views/upload/writers.py @@ -1,7 +1,7 @@ import abc import itertools from collections import defaultdict -from typing import List +from typing import Any, Dict, List from django.conf import settings @@ -17,6 +17,10 @@ class Writer(abc.ABC): """Save the read contents to DB.""" raise NotImplementedError('Please implement this method in the subclass.') + def errors(self) -> List[Dict[Any, Any]]: + """Return errors.""" + raise NotImplementedError('Please implement this method in the subclass.') + def group_by_class(instances): groups = defaultdict(list) @@ -97,9 +101,9 @@ class BulkWriter(Writer): self._errors.extend(reader.errors) @property - def errors(self) -> List[FileParseException]: + def errors(self) -> List[Dict[Any, Any]]: self._errors.sort(key=lambda e: e.line_num) - return self._errors + return [error.dict() for error in self._errors] def create(self, project: Project, user): self.examples.save_label(project)