Update query.py

Fixed crash on prefetch_related. See https://code.djangoproject.com/ticket/19607