Peewee Fetching Queries regardless of the conditions met

8 views
Skip to first unread message

Random Dude

unread,
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 = datetime.now()
CurrentTime = timestamp.strftime(r"%H:%M")
#CurrentTime prints out 7:10

query = database.Infraction.select().where(database.Infraction.MuteTimeRelease == 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

unread,
Apr 26, 2021, 2:59:45 PM4/26/21
to peewe...@googlegroups.com
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 peewee-orm+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/peewee-orm/b4097bdc-7b28-4d64-a42e-c37003065eacn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages