[Audio] Fix UnboundLocalError in edge case (#5394)

* Fix UnboundLocalError in edge case

* Fix typehint for fetch

* Style
This commit is contained in:
Flame442 2022-01-12 12:20:22 -05:00 committed by GitHub
parent 05cd11b657
commit b05933274a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -84,7 +84,9 @@ class PlaylistWrapper:
table = 2 table = 2
return table return table
async def fetch(self, scope: str, playlist_id: int, scope_id: int) -> PlaylistFetchResult: async def fetch(
self, scope: str, playlist_id: int, scope_id: int
) -> Optional[PlaylistFetchResult]:
"""Fetch a single playlist.""" """Fetch a single playlist."""
scope_type = self.get_scope_type(scope) scope_type = self.get_scope_type(scope)
@ -107,7 +109,8 @@ class PlaylistWrapper:
try: try:
row_result = future.result() row_result = future.result()
except Exception as exc: except Exception as exc:
debug_exc_log(log, exc, "Failed to completed playlist fetch from database") debug_exc_log(log, exc, "Failed to complete playlist fetch from database")
return None
row = row_result.fetchone() row = row_result.fetchone()
if row: if row:
row = PlaylistFetchResult(*row) row = PlaylistFetchResult(*row)
@ -139,7 +142,7 @@ class PlaylistWrapper:
try: try:
row_result = future.result() row_result = future.result()
except Exception as exc: except Exception as exc:
debug_exc_log(log, exc, "Failed to completed playlist fetch from database") debug_exc_log(log, exc, "Failed to complete playlist fetch from database")
return [] return []
else: else:
for future in concurrent.futures.as_completed( for future in concurrent.futures.as_completed(
@ -154,7 +157,7 @@ class PlaylistWrapper:
try: try:
row_result = future.result() row_result = future.result()
except Exception as exc: except Exception as exc:
debug_exc_log(log, exc, "Failed to completed playlist fetch from database") debug_exc_log(log, exc, "Failed to complete playlist fetch from database")
return [] return []
async for row in AsyncIter(row_result): async for row in AsyncIter(row_result):
output.append(PlaylistFetchResult(*row)) output.append(PlaylistFetchResult(*row))
@ -191,7 +194,8 @@ class PlaylistWrapper:
try: try:
row_result = future.result() row_result = future.result()
except Exception as exc: except Exception as exc:
debug_exc_log(log, exc, "Failed to completed fetch from database") debug_exc_log(log, exc, "Failed to complete fetch from database")
return []
async for row in AsyncIter(row_result): async for row in AsyncIter(row_result):
output.append(PlaylistFetchResult(*row)) output.append(PlaylistFetchResult(*row))