Document that functions in QuerySets' parameters are eagerly evaluated.
|Reported by:||liangent||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
if i write code like this:
qs = MyModel.objects.filter(dt__lte=datetime.datetime.now)
and execute it at time A, then save
later, at time B, i call
for obj in qs to get the object list. as the documentation says, database query is executed at time B. however, it seems that the value of
dt__lte was fetched at time A (ie.
datetime.datetime.now was evaluated at time A), and i think
datetime.datetime.now should be evaluated at time B (if i wrote
qs = MyModel.objects.filter(dt__lte=datetime.datetime.now())
, it should be evaluated at time A). it seems to go against "QuerySets are lazy", doesn't it?
Change History (9)
comment:1 Changed 8 years ago by
|Component:||Database layer (models, ORM) → Documentation|
|Status:||new → closed|
|Summary:||functions as QuerySets' parameters are not lazy → Docuemtn that functions in QuerySets' parameters are eagerly evaluated.|
|Triage Stage:||Unreviewed → Accepted|
comment:2 Changed 8 years ago by
|Summary:||Docuemtn that functions in QuerySets' parameters are eagerly evaluated. → Document that functions in QuerySets' parameters are eagerly evaluated.|