Browse Source

Fix errors property in Writer

It needs to return serializable object.
pull/1619/head
Hironsan 3 years ago
parent
commit
268d583eb5
1 changed files with 7 additions and 3 deletions
  1. 10
      backend/api/views/upload/writers.py

10
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)

Loading…
Cancel
Save