#28107: Can't perform annotation on related table when un-managed model is 
backed
by a DB view
-------------------------------------+-------------------------------------
     Reporter:  powderflask          |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  QuerySet.extra       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 From what I understood you are still on 1.8 but this patch will only be
 available in a couple of months when 2.0 is released.

 To get this fixed on your side in the mean time you'll have to define your
 own `django.db.backends.postgresql.base.DatabaseWrapper` subclass but it's
 not as intimidating as it sounds.

 Simply define a `DatabaseWrapper` subclass in a `chosen_module_name.base`
 module that extends the aforementioned class and set it's `features_class`
 attribute to a subclass of
 `django.db.backends.postgresql.features.DatabaseFeatures` with
 `allows_group_by_selected_pks = False`

 {{{
 django.db.backends.postgresql import base, features

 class DatabaseWrapper(base.DatabaseWrapper):
     class features_class(features.DatabaseFeatures):
         allows_group_by_selected_pks = False
 }}}

 Note that this disable the optimization all together. If you want to keep
 the optimization for managed models you'll have to define your own
 `SQLCompiler` subclass and override the `collapse_group_by` method which
 is a bit harder. I suggest you have a look
 
[https://github.com/django/django/blob/e7afef13f594eb667f2709c0ef7bca98452ab32b/django/db/backends/mysql/operations.py#L10
 how it's done for the MySQL backend] to figure it out.

 I suggest you have a look at how [https://github.com/carljm/django-
 transaction-hooks django-transaction-hooks] did it if you need a more
 concrete example.

--
Ticket URL: <https://code.djangoproject.com/ticket/28107#comment:12>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.c1151c4ecb8046625f5c0a1563c9cf50%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to