From f75dd9d1ebb8f3cf55d5cac1192c84648606c081 Mon Sep 17 00:00:00 2001 From: Arjun Choudhary Date: Tue, 26 Mar 2024 16:54:17 +0000 Subject: [PATCH 1/4] fix: incorrect status on data import - Used to show the status as "Not Started" if a prior import session was partially successful - `data_import_list.js` needs some rethinking just displaying the past few logs isn't super helpful the import logs aren't individually identifiable on that screen - could start deleting the logs of a previously failed imported record, if it's successful on a subsequent run or atleast flag it to not display it Refer to internal ticket 9486 and 12166 for further information --- .../core/doctype/data_import/data_import_list.js | 4 ---- frappe/core/doctype/data_import/importer.py | 16 +++++++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/frappe/core/doctype/data_import/data_import_list.js b/frappe/core/doctype/data_import/data_import_list.js index a16478cdb1..5aa2ece6d5 100644 --- a/frappe/core/doctype/data_import/data_import_list.js +++ b/frappe/core/doctype/data_import/data_import_list.js @@ -27,10 +27,6 @@ frappe.listview_settings["Data Import"] = { if (imports_in_progress.includes(doc.name)) { status = "In Progress"; } - if (status === "Pending") { - status = "Not Started"; - } - return [__(status), colors[status], "status,=," + doc.status]; }, formatters: { diff --git a/frappe/core/doctype/data_import/importer.py b/frappe/core/doctype/data_import/importer.py index 4f8d42bd28..8822f9132d 100644 --- a/frappe/core/doctype/data_import/importer.py +++ b/frappe/core/doctype/data_import/importer.py @@ -213,12 +213,18 @@ class Importer: ) # set status - failures = [log for log in import_log if not log.get("success")] - if len(failures) == total_payload_count: - status = "Pending" - elif len(failures) > 0: + successes = [] + failures = [] + for log in import_log: + if log.get("success"): + successes.append(log) + else: + failures.append(log) + if len(failures) >= total_payload_count and len(successes) == 0: + status = "Error" + elif len(failures) > 0 and len(successes) > 0: status = "Partial Success" - else: + elif len(len(successes) == total_payload_count): status = "Success" if self.console: From f22120190d28241aac963df291de1db8bb04b7f1 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 28 Mar 2024 14:48:10 +0530 Subject: [PATCH 2/4] fix: Correct logic for comlete success --- frappe/core/doctype/data_import/importer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/core/doctype/data_import/importer.py b/frappe/core/doctype/data_import/importer.py index 8822f9132d..7aa89aed28 100644 --- a/frappe/core/doctype/data_import/importer.py +++ b/frappe/core/doctype/data_import/importer.py @@ -221,10 +221,10 @@ class Importer: else: failures.append(log) if len(failures) >= total_payload_count and len(successes) == 0: - status = "Error" + status = "Error" elif len(failures) > 0 and len(successes) > 0: status = "Partial Success" - elif len(len(successes) == total_payload_count): + elif len(successes) == total_payload_count: status = "Success" if self.console: From 2710c288707171b9e1c04ca19bf1958e5bbc98d6 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 28 Mar 2024 15:14:56 +0530 Subject: [PATCH 3/4] fix(importer): set `Pending` status as a fallback Will match scenarios like success == failed == 0 Signed-off-by: Akhil Narang --- frappe/core/doctype/data_import/importer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frappe/core/doctype/data_import/importer.py b/frappe/core/doctype/data_import/importer.py index 7aa89aed28..afc9b9487a 100644 --- a/frappe/core/doctype/data_import/importer.py +++ b/frappe/core/doctype/data_import/importer.py @@ -226,6 +226,8 @@ class Importer: status = "Partial Success" elif len(successes) == total_payload_count: status = "Success" + else: + status = "Pending" if self.console: self.print_import_log(import_log) From 9f7c385b112c26a36860deb7c457e627baafb700 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 28 Mar 2024 15:24:29 +0530 Subject: [PATCH 4/4] fix: erase logs in case of complete failure --- frappe/core/doctype/data_import/importer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frappe/core/doctype/data_import/importer.py b/frappe/core/doctype/data_import/importer.py index afc9b9487a..a177d85c66 100644 --- a/frappe/core/doctype/data_import/importer.py +++ b/frappe/core/doctype/data_import/importer.py @@ -102,9 +102,13 @@ class Importer: log_index = 0 # Do not remove rows in case of retry after an error or pending data import - if self.data_import.status == "Partial Success" and len(import_log) >= self.data_import.payload_count: + if ( + self.data_import.status in ("Partial Success", "Error") + and len(import_log) >= self.data_import.payload_count + ): # remove previous failures from import log only in case of retry after partial success import_log = [log for log in import_log if log.get("success")] + frappe.db.delete("Data Import Log", {"success": 0, "data_import": self.data_import.name}) # get successfully imported rows imported_rows = []