Thanks to Christian Oudard for the report and tests. Backpatch of [cafb2669] Conflicts: django/db/models/sql/compiler.py