Backpatch of 5e1f4656b98816c96a1cc051224c1b699db480e0 from master. Conflicts: django/db/models/sql/query.py tests/queries/models.py tests/queries/tests.py
Backpatch of 5e1f4656b98816c96a1cc051224c1b699db480e0 from master. Conflicts: django/db/models/sql/query.py tests/queries/models.py tests/queries/tests.py