From dd7d4ebc2d2939a7960ad150aeecb285ab893691 Mon Sep 17 00:00:00 2001 From: Aditya Sridhar Date: Thu, 19 Sep 2024 17:38:53 -0400 Subject: [PATCH 1/5] fix: update to open file as binary --- python/src/functions/generate_treasury_report.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/src/functions/generate_treasury_report.py b/python/src/functions/generate_treasury_report.py index 96052e4b..ab7c7604 100644 --- a/python/src/functions/generate_treasury_report.py +++ b/python/src/functions/generate_treasury_report.py @@ -216,7 +216,7 @@ def process_event(payload: ProjectLambdaPayload, logger: structlog.stdlib.BoundL ### 5) Save data # Output XLSX file - with tempfile.NamedTemporaryFile("r+") as new_output_file: + with tempfile.NamedTemporaryFile("rb+") as new_output_file: output_workbook.save(new_output_file.name) upload_generated_file_to_s3( client=s3_client, @@ -229,7 +229,7 @@ def process_event(payload: ProjectLambdaPayload, logger: structlog.stdlib.BoundL file=new_output_file, ) # Output CSV file for treasury - with tempfile.NamedTemporaryFile("r+") as csv_file: + with tempfile.NamedTemporaryFile("rb+") as csv_file: convert_xlsx_to_csv(csv_file, output_workbook, highest_row_num) upload_generated_file_to_s3( client=s3_client, From 57b8b44763ab95f1483ed3ab202d3c9dce534f5c Mon Sep 17 00:00:00 2001 From: Aditya Sridhar Date: Fri, 20 Sep 2024 14:15:14 -0400 Subject: [PATCH 2/5] fix: change tempfile from bytes to string for csv --- python/src/functions/generate_treasury_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/src/functions/generate_treasury_report.py b/python/src/functions/generate_treasury_report.py index ab7c7604..2f01f92d 100644 --- a/python/src/functions/generate_treasury_report.py +++ b/python/src/functions/generate_treasury_report.py @@ -229,7 +229,7 @@ def process_event(payload: ProjectLambdaPayload, logger: structlog.stdlib.BoundL file=new_output_file, ) # Output CSV file for treasury - with tempfile.NamedTemporaryFile("rb+") as csv_file: + with tempfile.NamedTemporaryFile("r+") as csv_file: convert_xlsx_to_csv(csv_file, output_workbook, highest_row_num) upload_generated_file_to_s3( client=s3_client, From 32c0e4998340135f65006216b346c16c06ca64b5 Mon Sep 17 00:00:00 2001 From: Aditya Sridhar Date: Fri, 20 Sep 2024 14:18:02 -0400 Subject: [PATCH 3/5] fix: ensure csv file is opened as a string not binary --- python/src/functions/generate_treasury_report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/src/functions/generate_treasury_report.py b/python/src/functions/generate_treasury_report.py index ab7c7604..2f01f92d 100644 --- a/python/src/functions/generate_treasury_report.py +++ b/python/src/functions/generate_treasury_report.py @@ -229,7 +229,7 @@ def process_event(payload: ProjectLambdaPayload, logger: structlog.stdlib.BoundL file=new_output_file, ) # Output CSV file for treasury - with tempfile.NamedTemporaryFile("rb+") as csv_file: + with tempfile.NamedTemporaryFile("r+") as csv_file: convert_xlsx_to_csv(csv_file, output_workbook, highest_row_num) upload_generated_file_to_s3( client=s3_client, From e7e81d7c1633c6d87b3d92a0be5c19500772dd75 Mon Sep 17 00:00:00 2001 From: Aditya Sridhar Date: Fri, 20 Sep 2024 14:24:46 -0400 Subject: [PATCH 4/5] fix: typing --- python/src/lib/workbook_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/src/lib/workbook_utils.py b/python/src/lib/workbook_utils.py index 6aa87ab9..40216fed 100644 --- a/python/src/lib/workbook_utils.py +++ b/python/src/lib/workbook_utils.py @@ -1,6 +1,6 @@ import csv from tempfile import _TemporaryFileWrapper -from typing import IO, Optional, Union +from typing import Optional from openpyxl import Workbook from openpyxl.worksheet.worksheet import Worksheet @@ -19,8 +19,8 @@ def escape_for_csv(text: Optional[str]): def convert_xlsx_to_csv( - csv_file: Union[IO[bytes], _TemporaryFileWrapper], - file: Union[IO[bytes], Workbook], + csv_file: _TemporaryFileWrapper[str], + file: Workbook, num_rows: int, ): """ From 527ca2d3e49991aadbfed816a8629456da54af84 Mon Sep 17 00:00:00 2001 From: Aditya Sridhar Date: Fri, 20 Sep 2024 14:33:24 -0400 Subject: [PATCH 5/5] fix: typing --- python/src/lib/workbook_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/src/lib/workbook_utils.py b/python/src/lib/workbook_utils.py index 40216fed..77143c8f 100644 --- a/python/src/lib/workbook_utils.py +++ b/python/src/lib/workbook_utils.py @@ -19,7 +19,7 @@ def escape_for_csv(text: Optional[str]): def convert_xlsx_to_csv( - csv_file: _TemporaryFileWrapper[str], + csv_file: "_TemporaryFileWrapper[str]", file: Workbook, num_rows: int, ):