def handleError(self, reason): with transaction.commit_manually(): try: result = Result.objects.get(execution=self.execution, page=self.page, validator=self.validator) errors_json = result.description except: result = Result(execution=self.execution, page=self.page, validator=self.validator) errors_json = { "page": self.response.url, "errors": [] } errors_json['errors'].append({ "error": reason.getErrorMessage() }) result.description = errors_json result.save() transaction.commit()