Skip to content

Commit

Permalink
Fix: ensure CSV file is opened as string and not binary (#435)
Browse files Browse the repository at this point in the history
* fix: update to open file as binary

* fix: change tempfile from bytes to string for csv

* fix: ensure csv file is opened as a string not binary

* fix: typing
  • Loading branch information
as1729 authored Sep 20, 2024
1 parent 60eadf0 commit 10ed4d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/src/functions/generate_treasury_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions python/src/lib/workbook_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
):
"""
Expand Down

0 comments on commit 10ed4d7

Please sign in to comment.