def text_log_errors(self, request, project, pk=None): """ Gets a list of steps associated with this job """ try: job = Job.objects.get(repository__name=project, id=pk) except Job.DoesNotExist: return Response("No job with id: {0}".format(pk), status=HTTP_404_NOT_FOUND) textlog_errors = (TextLogError.objects.filter( step__job=job).order_by('id')) return Response( serializers.TextLogErrorSerializer(textlog_errors, many=True, read_only=True).data)
def text_log_errors(self, request, project, pk=None): """ Gets a list of error lines associated with this job """ try: job = Job.objects.get(repository__name=project, id=pk) except Job.DoesNotExist: return Response("No job with id: {0}".format(pk), status=HTTP_404_NOT_FOUND) textlog_errors = (TextLogError.objects.filter(job=job).select_related( "_metadata", "_metadata__failure_line").prefetch_related( "classified_failures", "matches").order_by('id')) return Response( serializers.TextLogErrorSerializer(textlog_errors, many=True, read_only=True).data)
def _update(self, data, user, many=True): ids = [] error_line_ids = set() classification_ids = set() bug_number_classifications = {} for item in data: line_id = item.get("id") if line_id is None: return "No text log error id provided", HTTP_400_BAD_REQUEST try: line_id = int(line_id) except ValueError: return "Text log error id was not an integer", HTTP_400_BAD_REQUEST error_line_ids.add(line_id) classification_id = item.get("best_classification") if classification_id is not None: classification_ids.add(classification_id) bug_number = item.get("bug_number") if (not classification_id and bug_number is not None and bug_number not in bug_number_classifications): bug_number_classifications[bug_number], _ = ( ClassifiedFailure.objects.get_or_create(bug_number=bug_number)) ids.append((line_id, classification_id, bug_number)) error_lines = as_dict( TextLogError.objects .prefetch_related('classified_failures') .filter(id__in=error_line_ids), "id") if len(error_lines) != len(error_line_ids): missing = error_line_ids - set(error_lines.keys()) return ("No text log error with id: {0}".format(", ".join(missing)), HTTP_404_NOT_FOUND) classifications = as_dict( ClassifiedFailure.objects.filter(id__in=classification_ids), "id") if len(classifications) != len(classification_ids): missing = classification_ids - set(classifications.keys()) return ("No classification with id: {0}".format(", ".join(missing)), HTTP_404_NOT_FOUND) for line_id, classification_id, bug_number in ids: logger.debug("line_id: %s, classification_id: %s, bug_number: %s" % (line_id, classification_id, bug_number)) error_line = error_lines[line_id] if classification_id is not None: logger.debug("Using classification id") classification = classifications[classification_id] if bug_number is not None and bug_number != classification.bug_number: logger.debug("Updating classification bug number") classification = classification.set_bug(bug_number) elif bug_number is not None: logger.debug("Using bug number") classification = bug_number_classifications[bug_number] else: logger.debug("Using null classification") classification = None error_line.mark_best_classification_verified(classification) error_line.step.job.update_after_verification(user) # Force failure line to be reloaded, including .classified_failures rv = (TextLogError.objects .prefetch_related('classified_failures') .filter(id__in=error_line_ids)) if not many: rv = rv[0] return (serializers.TextLogErrorSerializer(rv, many=many).data, HTTP_200_OK)