Skip to content

Commit

Permalink
fix: Add missing awaits on read/write for async opened files
Browse files Browse the repository at this point in the history
  • Loading branch information
adamantike committed Jul 27, 2024
1 parent c5b150c commit d1fda90
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions backend/endpoints/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ async def add_collection(
artwork_file = artwork.file.read()
file_location_s = f"{artwork_path}/small.{file_ext}"
async with await open_file(file_location_s, "wb+") as artwork_s:
artwork_s.write(artwork_file)
await artwork_s.write(artwork_file)
fs_resource_handler.resize_cover_to_small(file_location_s)

file_location_l = f"{artwork_path}/big.{file_ext}"
async with await open_file(file_location_l, "wb+") as artwork_l:
artwork_l.write(artwork_file)
await artwork_l.write(artwork_file)
else:
path_cover_s, path_cover_l = await fs_resource_handler.get_cover(
overwrite=True,
Expand Down Expand Up @@ -185,12 +185,12 @@ async def update_collection(
artwork_file = artwork.file.read()
file_location_s = f"{artwork_path}/small.{file_ext}"
async with await open_file(file_location_s, "wb+") as artwork_s:
artwork_s.write(artwork_file)
await artwork_s.write(artwork_file)
fs_resource_handler.resize_cover_to_small(file_location_s)

file_location_l = f"{artwork_path}/big.{file_ext}"
async with await open_file(file_location_l, "wb+") as artwork_l:
artwork_l.write(artwork_file)
await artwork_l.write(artwork_file)
cleaned_data.update({"url_cover": ""})
else:
if data.get("url_cover", "") != collection.url_cover or not (
Expand Down
6 changes: 3 additions & 3 deletions backend/endpoints/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def add_roms(
chunk = rom.file.read(1024)
if not chunk:
break
f.write(chunk)
await f.write(chunk)

uploaded_roms.append(rom.filename)

Expand Down Expand Up @@ -385,12 +385,12 @@ async def update_rom(
artwork_file = artwork.file.read()
file_location_s = f"{artwork_path}/small.{file_ext}"
async with await open_file(file_location_s, "wb+") as artwork_s:
artwork_s.write(artwork_file)
await artwork_s.write(artwork_file)
fs_resource_handler.resize_cover_to_small(file_location_s)

file_location_l = f"{artwork_path}/big.{file_ext}"
async with await open_file(file_location_l, "wb+") as artwork_l:
artwork_l.write(artwork_file)
await artwork_l.write(artwork_file)
cleaned_data.update({"url_cover": ""})
else:
if data.get("url_cover", "") != rom.url_cover or not (
Expand Down
2 changes: 1 addition & 1 deletion backend/endpoints/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async def update_user(
async with await open_file(
f"{ASSETS_BASE_PATH}/{file_location}", "wb+"
) as file_object:
file_object.write(form_data.avatar.file.read())
await file_object.write(form_data.avatar.file.read())

if cleaned_data:
db_user_handler.update_user(id, cleaned_data)
Expand Down

0 comments on commit d1fda90

Please sign in to comment.