#28107: Can't perform annotation on related table when relation between tables
not
on primary key
-------------------------------------+-------------------------------------
Reporter: powderflask | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: QuerySet.extra | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by powderflask):
* status: closed => new
* resolution: worksforme =>
Comment:
OK - that's got it. Yep -- this issues occurs when at least one of the
models in the aggregation query is un-managed and backed by a DB view
rather than a table.
Attached is a zip of a simple django app that runs in a default django
container, demonstrates the issue:
1) Demonstrate these weird relations work with models backed by DB tables:
- {{{ INSTALLED_APPS = [ 'issue28107.apps.Issue28107Config', ... ] }}}
- configure / create postgre DB,
- manage.py migrate
- run the unit-test -- it should pass
2) Replace table with view (created by migrations)
- in models.py, remove 2 comments from Treatment.Meta:
{{{
managed = False
db_table = 'issue28107_treatment_vw'
}}}
- re-run unit-test -- it should fail:
{{{ column "issue28107_treatment_vw.globalid" must appear in the GROUP BY
clause or be used in an aggregate function }}}
This is a backwards-compatibility issue -- this worked at least up to
django1.8
I have no idea where to begin with this in terms of suggesting a patch --
any pointers?
thank you for the quick reply and suggestions -- awesome.
--
Ticket URL: <https://code.djangoproject.com/ticket/28107#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 [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.0ae359029e269da6cad39aa26e7b0c0a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.