diff --git a/apps/netsuite/exceptions.py b/apps/netsuite/exceptions.py index 815bb162..6b72a25b 100644 --- a/apps/netsuite/exceptions.py +++ b/apps/netsuite/exceptions.py @@ -43,7 +43,7 @@ def __handle_netsuite_connection_error(expense_group: ExpenseGroup, task_log: Ta } if expense_group: - error, created = Error.objects.update_or_create( + error, _ = Error.objects.update_or_create( workspace_id=expense_group.workspace_id, expense_group=expense_group, defaults={ @@ -53,7 +53,7 @@ def __handle_netsuite_connection_error(expense_group: ExpenseGroup, task_log: Ta 'is_resolved': False }) - error.increase_repetition_count_by_one(created) + error.increase_repetition_count_by_one() task_log.status = 'FAILED' task_log.detail = detail @@ -139,7 +139,7 @@ def wrapper(*args): if parsed_message: is_parsed = True all_details[-1]['message'] = parsed_message - error, created = Error.objects.update_or_create( + error, _ = Error.objects.update_or_create( workspace_id=expense_group.workspace_id, expense_group=expense_group, defaults={ @@ -152,7 +152,7 @@ def wrapper(*args): } ) - error.increase_repetition_count_by_one(created) + error.increase_repetition_count_by_one() task_log.detail = all_details @@ -172,18 +172,17 @@ def wrapper(*args): except NetSuiteRateLimitError: if not payment: - error, created = Error.objects.update_or_create( + error, _ = Error.objects.update_or_create( workspace_id=expense_group.workspace_id, expense_group=expense_group, defaults={ 'type': 'NETSUITE_ERROR', 'error_title': netsuite_error_message, 'error_detail': f'Rate limit error, workspace_id - {expense_group.workspace_id}', - 'repetition_count': F('repetition_count') + 1, 'is_resolved': False } ) - error.increase_repetition_count_by_one(created) + error.increase_repetition_count_by_one() logger.info('Rate limit error, workspace_id - %s', workspace_id if payment else expense_group.workspace_id) task_log.status = 'FAILED' @@ -208,18 +207,17 @@ def wrapper(*args): task_log.detail = detail task_log.save() - error, created = Error.objects.update_or_create( + error, _ = Error.objects.update_or_create( workspace_id=workspace_id, expense_group=expense_group, defaults={ 'type': 'NETSUITE_ERROR', 'error_title': 'Something unexpected has happened during export', 'error_detail': f'{detail}, workspace_id - {workspace_id}', - 'repetition_count': F('repetition_count') + 1, 'is_resolved': False } ) - error.increase_repetition_count_by_one(created) + error.increase_repetition_count_by_one() except Exception: error = traceback.format_exc() diff --git a/apps/netsuite/tasks.py b/apps/netsuite/tasks.py index e94a212b..42044cd6 100644 --- a/apps/netsuite/tasks.py +++ b/apps/netsuite/tasks.py @@ -825,7 +825,7 @@ def __validate_tax_group_mapping(expense_group: ExpenseGroup, configuration: Con }) if tax_group: - error, created = Error.objects.update_or_create( + error, _ = Error.objects.update_or_create( workspace_id=tax_group.workspace_id, expense_attribute=tax_group, defaults={ @@ -836,7 +836,7 @@ def __validate_tax_group_mapping(expense_group: ExpenseGroup, configuration: Con } ) - error.increase_repetition_count_by_one(created) + error.increase_repetition_count_by_one() row = row + 1 @@ -916,7 +916,7 @@ def __validate_employee_mapping(expense_group: ExpenseGroup, configuration: Conf }) if employee: - error, created = Error.objects.update_or_create( + error, _ = Error.objects.update_or_create( workspace_id=expense_group.workspace_id, expense_attribute=employee, defaults={ @@ -926,7 +926,7 @@ def __validate_employee_mapping(expense_group: ExpenseGroup, configuration: Conf 'is_resolved': False } ) - error.increase_repetition_count_by_one(created) + error.increase_repetition_count_by_one() return bulk_errors @@ -973,7 +973,7 @@ def __validate_category_mapping(expense_group: ExpenseGroup, configuration: Conf }) if category_attribute: - error, created = Error.objects.update_or_create( + error, _ = Error.objects.update_or_create( workspace_id=expense_group.workspace_id, expense_attribute=category_attribute, defaults={ @@ -983,7 +983,7 @@ def __validate_category_mapping(expense_group: ExpenseGroup, configuration: Conf 'is_resolved': False } ) - error.increase_repetition_count_by_one(created) + error.increase_repetition_count_by_one() row = row + 1 diff --git a/apps/tasks/models.py b/apps/tasks/models.py index 803576b4..f713168f 100644 --- a/apps/tasks/models.py +++ b/apps/tasks/models.py @@ -86,14 +86,12 @@ class Error(models.Model): created_at = models.DateTimeField(auto_now_add=True, help_text='Created at datetime') updated_at = models.DateTimeField(auto_now=True, help_text='Updated at datetime') - - def increase_repetition_count_by_one(self, is_created: bool): + def increase_repetition_count_by_one(self): """ Increase the repetition count by 1. """ - if not is_created: - self.repetition_count += 1 - self.save() + self.repetition_count += 1 + self.save() class Meta: db_table = 'errors'