From f0952d0fbb73b6119de32ab94d1c8066282e7a78 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 11 Oct 2022 21:59:43 +0530 Subject: [PATCH] refactor: use file api to read import data (#18379) (#18382) * refactor: use file api for reading data in import * fix: remove unused import Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Co-authored-by: Faris Ansari Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> (cherry picked from commit 702e8674f94fde353ac12885f5782ea73ef75b6f) Co-authored-by: Ankush Menat --- .github/workflows/ui-tests.yml | 1 + frappe/core/doctype/data_import/importer.py | 9 ++++++--- frappe/core/doctype/file/file.py | 1 - 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ui-tests.yml b/.github/workflows/ui-tests.yml index 6a3d12d210..3ae8a35454 100644 --- a/.github/workflows/ui-tests.yml +++ b/.github/workflows/ui-tests.yml @@ -121,6 +121,7 @@ jobs: DB: mariadb - name: Verify yarn.lock + if: ${{ steps.check-build.outputs.build == 'strawberry' }} run: | cd ~/frappe-bench/apps/frappe yarn install --immutable --immutable-cache --check-cache diff --git a/frappe/core/doctype/data_import/importer.py b/frappe/core/doctype/data_import/importer.py index 57849e5cfc..ea90b24a6f 100644 --- a/frappe/core/doctype/data_import/importer.py +++ b/frappe/core/doctype/data_import/importer.py @@ -572,12 +572,15 @@ class ImportFile: ###### - def read_file(self, file_path): + def read_file(self, file_path: str): extn = os.path.splitext(file_path)[1][1:] file_content = None - with open(file_path, mode="rb") as f: - file_content = f.read() + + file_name = frappe.db.get_value("File", {"file_url": file_path}) + if file_name: + file = frappe.get_doc("File", file_name) + file_content = file.get_content() return file_content, extn diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index e1faf331d6..1518c72f95 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -422,7 +422,6 @@ class File(Document): return os.path.exists(self.get_full_path()) def get_content(self) -> bytes: - """Returns [`file_name`, `content`] for given file name `fname`""" if self.is_folder: frappe.throw(_("Cannot get file contents of a Folder"))