Changes between Initial Version and Version 11 of Ticket #28107


Ignore:
Timestamp:
Apr 29, 2017, 6:13:46 PM (7 years ago)
Author:
powderflask
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28107

    • Property Cc Simon Charette added
    • Property Has patch set
    • Property Triage Stage UnreviewedAccepted
    • Property Type UncategorizedBug
    • Property Version 1.11master
    • Property Summary Can't perform annotation on related table when relation between tables not on primary keyCan't perform annotation on related table when un-managed model is backed by a DB view
  • Ticket #28107 – Description

    initial v11  
    77{{{ qs.annotate(num_attachments=Count('attachments')) }}}
    88
    9 The root cause appears to be that the relation between the model and attachments tables uses a unique field ''other than the main model's primary key'' (I know -- told you it was ugly - ArcSDE does not really support relations, except they implement attachments with this odd ball ** sigh **). 
     9The root cause appears to be that the relation between an unmanaged model (backed by a DB View) and attachments tables uses a unique field ''other than the main model's primary key'' (I know -- told you it was ugly - ArcSDE does not really support relations, except they implement attachments with this odd ball ** sigh **). 
    1010The change in behaviour seems to manifest from #19259 (I believe django1.8 added all fields to the groupby clause).
    1111Since django now includes only the primary key in the groupby clause, postgresql won't do this aggregation across a relation that uses a non-pk field.
    1212
    1313I suspect there is a general issue here that aggregations on a related-table won't work in postgresql unless the relation is on the primary key field (so, yeah, basically this issue applies to almost no one, right...).   
     14UPDATE:  The root cause is actually that Postgresql treats Views differently than Tables w.r.t. what is required in the group by clause.
    1415
    1516Seems likely there is a better solution to this, but after a half-day of search / effort, I resorted to the following:
Back to Top