I’ve got a similar (but not identical) table in my test environment named Author. This is what I’m getting:
In : a=Author.objects.values('name').annotate(cnt=Count('name')).order_by('?')
In : print(a.query)
SELECT "fs_author"."name", COUNT("fs_author"."name") AS "cnt" FROM "fs_author" GROUP BY "fs_author"."name" ORDER BY RANDOM() ASC
This leads me to believe there’s some information associated with this that you’re not showing here.
What are you looking at that is indicating that Django is creating that sql?
How are you running that query? Is that something from your shell? In a view?
Is there a custom manager involved?
Is there anything else that might be affecting the query being generated?
I verified I’m getting the same results as you with Django 3.1, so this appears to be something that was fixed between 3.1 and 3.2.
I took a quick look through the release notes for 3.2, but I don’t see anything quickly that would explain the change in behavior. If you’re really interested, you could try searching through the issues to see if you can find when / where the patch was applied.