Fix check if election exists.
build_develop / build (push) Successful in 1m35s

Scalars doesn't return None if the thing doesn't exists while scalar does.
This commit is contained in:
2023-11-07 14:44:07 -05:00
parent 678fcd37e1
commit 4e8032823d
+7 -6
View File
@@ -49,10 +49,15 @@ class ViewCog(commands.Cog, name="View Commands"):
stmt = select(Votes).where(Votes.ElectionCycle == election_name) stmt = select(Votes).where(Votes.ElectionCycle == election_name)
with Session(engine) as session: with Session(engine) as session:
try: # Check if election exists.
if session.scalar(stmt) is None:
await interaction.response.send_message(
f"Invalid election: {election_name}.", ephemeral=True
)
return
votes = session.scalars(stmt) votes = session.scalars(stmt)
content = "" content = ""
for vote in votes: for vote in votes:
content += ( content += (
f"<@{vote.VoterId}> voted for <@{vote.VotedForId}>.\n" f"<@{vote.VoterId}> voted for <@{vote.VotedForId}>.\n"
@@ -61,10 +66,6 @@ class ViewCog(commands.Cog, name="View Commands"):
) )
await interaction.response.send_message(content=content, ephemeral=True) await interaction.response.send_message(content=content, ephemeral=True)
except:
await interaction.response.send_message(
f"Invalid election: {election_name}.", ephemeral=True
)
@votes.on_autocomplete("election_name") @votes.on_autocomplete("election_name")
async def election_autocomplete( async def election_autocomplete(