python - Unexpected behaviour in django queryset -
i have following code:
foo_list = foo.objects.all()[100:200] print foo_list[0].id print len(foo_list) print foo_list[0].id i expect result of first , third print eqaul not.how happen?
you're running "wontfix" issue @ https://code.djangoproject.com/ticket/9006 --
limit queries without order aren't guaranteed return consistent result sets
(depending on underlying db engine), , that's [0] indexing causing happen -- because despite misleading name foo_list not list, it's queryset itself! documented @ https://docs.djangoproject.com/en/1.7/ref/models/querysets/ ,
slicing unevaluated
querysetreturns unevaluatedqueryset
solution: make list:
foo_list = list(foo.objects.all()[100:200]) and live happily ever after:-)
Comments
Post a Comment