should prefetches all happen inside a transaction?
That all would depend on your databases default isolation level. Also recall please how, as a general rule, peewee doesn't use magic or do things based on what it "thinks" you might want. You have the tools to do your prefetching in an atomic block. If you always want this behavior, write a wrapper.
 > That all would depend on your databases default isolation level.

i don't think that's true.  two subsequent queries outside of a transaction don't have any consistency guarantees between them at any isolation level on any database.

> peewee doesn't use magic or do things based on what it "thinks" you might want

all APIs are doing what they think you want to a certain degree, in the sense that they have reasonable defaults and behavior.  anyone who makes a single API call to a peewee method would expect it to return an internally consistent collection of objects.  i shouldn't have to know / worry about internal implementation details in order to get correct data, vs. this obvious race condition.  "it's usually right" arguments aside.
 > i shouldn't have to know / worry about internal implementation details in order to get correct data

In that case you should wrap your code in an `atomic()` block.
 i get that that's an option.  i'm arguing that that should be the default because as is the results are only "usually" right.  :)

i would argue they should, as otherwise there is no guarantee we're getting a read-consistent view of the data.  seems like a simple fix on the face, given that peewee can already handle nesting `atomic()`.
