From 65c17f11b22261663752f47d6369c8edd679e677 Mon Sep 17 00:00:00 2001 From: Conatum Date: Fri, 30 Jun 2023 12:34:21 +0300 Subject: [PATCH] fix (schedule): Various bug fixes. --- src/modules/schedule/cog.py | 3 ++- src/modules/schedule/core/timeslot.py | 29 ++++++++++++++------------- src/utils/data.py | 3 +++ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/modules/schedule/cog.py b/src/modules/schedule/cog.py index 6cf93ae5..4883117a 100644 --- a/src/modules/schedule/cog.py +++ b/src/modules/schedule/cog.py @@ -489,7 +489,8 @@ class ScheduleCog(LionCog): session = slot.sessions.get(guildid, None) if session is None: # Create a new session in the slot and set it up - session = await slot.load_sessions(session_data[guildid, slotid]) + sessions = await slot.load_sessions([session_data[guildid, slotid]]) + session = sessions[guildid] slot.sessions[guildid] = session if slot.closing.is_set(): # This should never happen diff --git a/src/modules/schedule/core/timeslot.py b/src/modules/schedule/core/timeslot.py index a16640d8..d7bee672 100644 --- a/src/modules/schedule/core/timeslot.py +++ b/src/modules/schedule/core/timeslot.py @@ -210,20 +210,21 @@ class TimeSlot: await batchrun_per_second(coros, 5) # Save messageids - tmptable = TemporaryTable( - '_gid', '_sid', '_mid', - types=('BIGINT', 'INTEGER', 'BIGINT') - ) - tmptable.values = [ - (sg.data.guildid, sg.data.slotid, sg.messageid) - for sg in sessions - if sg.messageid is not None - ] - await Data.ScheduleSession.table.update_where( - guildid=tmptable['_gid'], slotid=tmptable['_sid'] - ).set( - messageid=tmptable['_mid'] - ).from_expr(tmptable) + if sessions: + tmptable = TemporaryTable( + '_gid', '_sid', '_mid', + types=('BIGINT', 'INTEGER', 'BIGINT') + ) + tmptable.values = [ + (sg.data.guildid, sg.data.slotid, sg.messageid) + for sg in sessions + if sg.messageid is not None + ] + await Data.ScheduleSession.table.update_where( + guildid=tmptable['_gid'], slotid=tmptable['_sid'] + ).set( + messageid=tmptable['_mid'] + ).from_expr(tmptable) except Exception: logger.exception( f"Unhandled exception while preparing timeslot ." diff --git a/src/utils/data.py b/src/utils/data.py index 2a8795b0..6be3680b 100644 --- a/src/utils/data.py +++ b/src/utils/data.py @@ -123,6 +123,9 @@ class TemporaryTable(Expression): AS name (col1, col2) """ + if not self.values: + raise ValueError("Cannot flatten CTE with no values.") + single_value = sql.SQL("({})").format(sql.SQL(", ").join(sql.Placeholder() for _ in self.columns)) if self.types: first_value = sql.SQL("({})").format(