Peewee Fetching Queries regardless of the conditions met

Skip to first unread message

Random Dude

Apr 26, 2021, 2:07:35 PM4/26/21
to peewee-orm
So I have a discord bot which basically loops every minute checking if a user needs to be unmuted. Currently I'm just storing their ID, the time for them to be unmuted, and if its an active mute. 

The problem right now is that every time the loop restarts, it always gets the next query regardless of the current time. So lets say the next mute was logged at 7:15 and currently its 7:10. Peewee just gets the next query regardless of the time condition not being met. 
I've checked the database and the time was being logged correctly.

This is my query statement:

timestamp =
CurrentTime = timestamp.strftime(r"%H:%M")
#CurrentTime prints out 7:10

query = == CurrentTime and database.Infraction.ActiveMute == "True").get() 
#Peewee brings back a record due at 7:15

What's even weirder is that it was able to access all of its attributes and im not sure why this is happening. 

Charles Leifer

Apr 26, 2021, 2:59:45 PM4/26/21
Had you spent the time writing this email reading the docs, you would have hopefully noticed that Peewee does not support the python keyword "and" ("or", or "not") to express logical AND in queries.

You must use the bitwise operator:

.where((MuteTimeRelease == CurrentTime) & (ActiveMute == True))

Why you are storing "True" as a string I will ignore... Also note the additional parentheses around each expression. These are required due to python's operator precedence.

You received this message because you are subscribed to the Google Groups "peewee-orm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages