#31097: StringAgg And ArrayAgg with filtering in subquery generates invalid
string_agg() SQL function call
-------------------------------------+-------------------------------------
     Reporter:  Laurent Tramoy       |                    Owner:  David
                                     |  Wobrock
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.postgres     |                  Version:  3.0
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by David Wobrock):

 * status:  new => assigned
 * owner:  (none) => David Wobrock


Comment:

 Hi, I'm claiming the ticket if nobody bothers.
 I already wrote a testcase that reproduced the bug and started to pin down
 the source of the issue.

 The first (very) technical info I found:
 It seems to be linked to the logic of relabeling aliases of the the filter
 clause in {{{django.db.models.sql.query.Query.change_aliases}}}, in the
 {{{self.where.relabel_aliases(change_map)}}} logic.
 The first node itself is a {{{WhereNode}}} containing {{{(AND: (NOT (AND:
 <django.db.models.lookups.Exact object at 0x7f9ea9bfc9b0>)))}}}
 When going down the filter tree, we first hit again a {{{WhereNode}}} with
 the negation: {{{(NOT (AND: <django.db.models.lookups.Exact object at
 0x7f9ea9bfc9b0>))}}} for our exclude clause.
 Finally coming to the {{{Exact}}} object, we relabel the left hand-side of
 the condition, being the {{{StringAgg}}}.
 This calls the
 {{{django.db.models.expressions.BaseExpression.relabeled_clone}}} where we
 depend on the fields found by {{{self.get_source_expressions()}}}

 Either, those source expressions are incomplete because of the way the
 {{{OrderableAggMixin}}} plays with the {{{self.get_source_expressions()}}}
 (not calling the super), or the {{{change_map}}} which is passed down is
 missing some potential aliases.

 I'll try to keep investigating and propose a patch in the coming weeks :)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31097#comment:3>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.b3aabc4a0f4529a531134e1c866b859f%40djangoproject.com.

Reply via email to