#27241: Annotate doesn't work with PostgreSQL views anymore -------------------------------------+------------------------------------- Reporter: jaap3 | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: master (models, ORM) | Severity: Normal | Resolution: Keywords: postgresql view | Triage Stage: Accepted aggregate annotate | Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by charettes):
* cc: charettes (added) * version: 1.10 => master * stage: Unreviewed => Accepted Comment: > Before the annotate() call, add only() naming all the fields. Or maybe even drop the PK, if that makes sense. The trick `only()` won't work as `pk` is always implicitly selected (`only('field')` == `only('field', 'pk')`). The only solution I can think of is disabling the optimization for unmanaged models but the real issue here is really that unmanaged models are not meant to be used to deal with database views. The fact that Django enforces the presence of a primary key and views are not allowed to have one really highlights the conceptual clash. As Django doesn't provide any way to interact with views and even suggests `managed` [https://docs.djangoproject.com/en/1.10/ref/models/options/#django.db.models.Options.managed can be used for this purpose] I think we should simply disable the optimization for this specific case. -- Ticket URL: <https://code.djangoproject.com/ticket/27241#comment:6> 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 post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.57b88374a219e922135d9a7d29c18513%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.