#32862: Order By in Postgres When Using Annotations Causes Ambiguous Field Name
-------------------------------+--------------------------------------
     Reporter:  Cody Williams  |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  Uncategorized  |                  Version:  3.0
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by Simon Charette):

 I guess the ORM could detect when a reference is ambiguous and inline the
 expression when it's the case but I'm not sure of the benefits versus the
 complexity it introduces.

 If you want to give a shot at writing a patch yourself the logic should
 live in `sql.SQLCompiler.get_order_by` and act upon expressions where
 `is_ref` is true.

 
https://github.com/django/django/blob/225d96533a8e05debd402a2bfe566487cc27d95f/django/db/models/sql/compiler.py#L381-L420

 I guess the logic could then be added in a
 `django.db.models.expressions.Ref.is_ambiguous(query: sql.Query) -> bool`
 method that would introspect `query.select` and `query.annotation_select`
 and be relied on `get_order_by`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32862#comment:1>
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/070.08c319f82e949ef23c4cbbadd268a385%40djangoproject.com.

Reply via email to