coleifer / peewee

a small, expressive orm -- supports postgresql, mysql, sqlite and cockroachdb
http://docs.peewee-orm.com/
MIT License
11.08k stars 1.37k forks source link

Wrong CursorWrapper __bool__ #2872

Closed fmazan closed 5 months ago

fmazan commented 5 months ago

A change introduced in https://github.com/coleifer/peewee/commit/148f1b76684af750db239a5220769d43260c57a5 causes incompatibility in the case of bool function is called before any row is fetched after execution or the row_cache is filled.

count = MyModel.select().count()  # 42
cursor = MyModel.select().for_update().execute()  # Does not have to be for_update, it's just for demo
# cursor.__bool__() == False
count = MyModel.select().count()  # 42
cursor = MyModel.select().for_update().execute()
list(cursor)
# cursor.__bool__() == True

Expected behavior from my point of view is the bool evaluation be True if the query succeeded.