#32007: AttributeError: 'WhereNode' object has no attribute 'copy' ------------------------------------------+------------------------ Reporter: Gordon Wrigley | Owner: nobody Type: Uncategorized | Status: new Component: Uncategorized | Version: 3.1 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | ------------------------------------------+------------------------ I think I've found a regression in 3.1, I'm seeing this across databases and Python versions but only on Django 3.1. With reference to the polls app the queryset I hit this on is essentially: {{{#!python Question.objects.values("question_text").annotate( pub_date__count=Count("pub_date", distinct=True), pub_date__is_null=ExpressionWrapper(Q(pub_date=None), output_field=BooleanField()) ).values("question_text", "pub_date__count", "pub_date__is_null") }}} This results in: {{{ ~\.venv\django_tutorial\lib\site-packages\django\db\models\query.py in annotate(self, *args, **kwargs) 1121 clone.query.group_by = True 1122 else: -> 1123 clone.query.set_group_by() 1124 break 1125
~\.venv\django_tutorial\lib\site-packages\django\db\models\sql\query.py in set_group_by(self, allow_aliases) 1979 if not allow_aliases or alias in column_names: 1980 alias = None -> 1981 group_by_cols = annotation.get_group_by_cols(alias=alias) 1982 group_by.extend(group_by_cols) 1983 self.group_by = tuple(group_by) ~\.venv\django_tutorial\lib\site-packages\django\db\models\expressions.py in get_group_by_cols(self, alias) 867 868 def get_group_by_cols(self, alias=None): --> 869 expression = self.expression.copy() 870 expression.output_field = self.output_field 871 return expression.get_group_by_cols(alias=alias) AttributeError: 'WhereNode' object has no attribute 'copy' }}} It's a bit of a dumb query but given my usecase https://pypi.org/project /django-data-browser/ that's a little beyond my control. Still it's kinda surprising that it worked on 3.0 and doesn't on 3.1. It can be simplified a bit and still get essentially the same result: {{{#!python Question.objects.annotate( pub_date__count=Count("pub_date", distinct=True), pub_date__is_null=ExpressionWrapper(Q(pub_date=None), output_field=BooleanField()) ) }}} Removing either of the annotate clauses "fixes" it. -- Ticket URL: <https://code.djangoproject.com/ticket/32007> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.10e4323bdfb24ac52639c7fa949ea294%40djangoproject.com.