Changes between Initial Version and Version 11 of Ticket #28107
- Timestamp:
- Apr 29, 2017, 6:13:46 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #28107
- Property Cc added
- Property Has patch set
- Property Triage Stage Unreviewed → Accepted
- Property Type Uncategorized → Bug
- Property Version 1.11 → master
- Property Summary Can't perform annotation on related table when relation between tables not on primary key → Can't perform annotation on related table when un-managed model is backed by a DB view
-
Ticket #28107 – Description
initial v11 7 7 {{{ qs.annotate(num_attachments=Count('attachments')) }}} 8 8 9 The root cause appears to be that the relation between the modeland 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 **).9 The 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 **). 10 10 The change in behaviour seems to manifest from #19259 (I believe django1.8 added all fields to the groupby clause). 11 11 Since 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. 12 12 13 13 I 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...). 14 UPDATE: The root cause is actually that Postgresql treats Views differently than Tables w.r.t. what is required in the group by clause. 14 15 15 16 Seems likely there is a better solution to this, but after a half-day of search / effort, I resorted to the following: