django annotate unexpected limit 21
As suggested by Iain in a comment above, a LIMIT 21 is automatically added when taking the repr()
of a queryset, which also happens implicitely when printing a queryset.
To get the full output, you can force the queryset into a list before printing, e.g. instead of print(qs)
you would write print(list(qs))
(which shows all data, but omits the queryset classname).
The relevant code is here and here:
REPR_OUTPUT_SIZE = 20def __repr__(self): data = list(self[:REPR_OUTPUT_SIZE + 1]) if len(data) > REPR_OUTPUT_SIZE: data[-1] = "...(remaining elements truncated)..." return '<%s %r>' % (self.__class__.__name__, data)
Note that the LIMIT 21 will also be present on queries generated by calling .get()
on a queryset, probably as a safeguard to returning a ton of data when you need just one (but the limit is not 1, to make sure you get a meaningful error when more than one is returned.
See here:
MAX_GET_RESULTS = 21