Skip to content

Commit

Permalink
flushing to ensure all data from the TextIOWrapper is written to the …
Browse files Browse the repository at this point in the history
…underlying BytesIO buffer
  • Loading branch information
jredrejo authored and nucleogenesis committed Jan 14, 2025
1 parent 8219fd3 commit a144f11
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kolibri/core/auth/management/commands/bulkexportusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def csv_file_generator(facility, filepath, overwrite=True):
csv_file = io.BytesIO()

with csv_file as f:
writer = csv.DictWriter(io.TextIOWrapper(f, encoding="utf-8"), header_labels)
buffer = io.TextIOWrapper(f, encoding="utf-8")
writer = csv.DictWriter(buffer, header_labels)
logger.info("Creating users csv file {filename}".format(filename=filepath))
writer.writeheader()
usernames = set()
Expand Down Expand Up @@ -207,6 +208,7 @@ def csv_file_generator(facility, filepath, overwrite=True):
usernames.add(item["username"])
yield item

buffer.flush() # Ensure all data is written to the underlying BytesIO
f.seek(0)
file = file_storage.save(filename, f)

Expand Down

0 comments on commit a144f11

Please sign in to comment.