Behaviour change in Django 5.2 queryset.values_list() for duplicate column names

Hi all,

There is a behaviour change in Django 5.2 but I’m posting here rather than filing a bug because I may have been previously relying on unsupported behaviour. I have query which does boils down to this:

qs = models.Employee.objects.values_list(‘username’, ‘username’, ‘company__legal_name’)

Notice the repeated “username”. On Django 5.1.6 and 5.1.7, each result from the queryset is a 3-tuple whereas on 5.2 this is a 2-tuple. I suspect this is related to the change mention in the release notes which reads:

The SELECT clause generated when using QuerySet.values() and QuerySet.values_list() now matches the specified order of the referenced expressions. Previously, the order was based on a set of counterintuitive rules which made query combination through methods such as QuerySet.union()unpredictable.

So, should I fix my code to handle the duplicate case, or is this a bug?

Thanks, Shaheed

This is a regression that will be fixed in 5.2.1, see notes.

Thanks for confirming!

1 Like