Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-29 Thread Django
#28107: Can't perform annotation on related table when relation between tables 
not
on primary key
-+-
 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):

 Sure go ahead!

--
Ticket URL: 
Django 
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/069.dee3997c1631d10e3c98f7d6bd5f4ddb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-29 Thread Django
#28107: Can't perform annotation on related table when relation between tables 
not
on primary key
-+-
 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 powderflask):

 Should I change the title of this issue to reflect the root cause was a
 model backed by a View?

--
Ticket URL: 
Django 
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/069.049677c4e2cb3d6ee402b214eb39aecb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-29 Thread Django
#28107: Can't perform annotation on related table when relation between tables 
not
on primary key
-+-
 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
-+-
Changes (by Simon Charette):

 * has_patch:  0 => 1
 * version:  1.11 => master
 * type:  Uncategorized => Bug
 * stage:  Unreviewed => Accepted


Comment:

 Thanks to your detailed report writing a patch was easy.

 [https://github.com/django/django/pull/8441 PR]

--
Ticket URL: 
Django 
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/069.667653d30090e084d781353e5c2da3b9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-28 Thread Django
#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
-+-

Comment (by powderflask):

 It occurs to me that if there were some way to force values into the
 group-by clause, that would serve as a reasonable workaround, given this
 is bound to be a fairly rare use-case.
 I did read some hacks that did this in 1.8, but it looks like
 query.group_by is now a boolean rather than a list of fields...  was
 pretty ugly anyhow.

 But I'm not missing something more obvious here am I -- like an extra()
 clause or something that could force the offending aggregate fields into
 the group_by clause?

--
Ticket URL: 
Django 
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/069.c20d826ec8974a4422fbdf1a5bc74f55%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-28 Thread Django
#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: 
Django 
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/069.0ae359029e269da6cad39aa26e7b0c0a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-28 Thread Django
#28107: Can't perform annotation on related table when relation between tables 
not
on primary key
-+-
 Reporter:  powderflask  |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  1.11
  (models, ORM)  |   Resolution:
 Severity:  Normal   |  worksforme
 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):

 * Attachment "issue28107.zip" added.

 small django app with models, migrations, and tests that illustrate the
 issue

--
Ticket URL: 
Django 
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/069.40dcb932e934d9e0873e6d4d5a1d88d1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-28 Thread Django
#28107: Can't perform annotation on related table when relation between tables 
not
on primary key
-+-
 Reporter:  powderflask  |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  1.11
  (models, ORM)  |   Resolution:
 Severity:  Normal   |  worksforme
 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
-+-

Comment (by Simon Charette):

 powderflask, if this happens to be the source of the issue and you are
 using un-managed models (`_meta.managed = False`) maybe we could branch on
 that to prevent the optimization.

--
Ticket URL: 
Django 
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/069.d56f077d01b17fc8edb16695b862937b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-28 Thread Django
#28107: Can't perform annotation on related table when relation between tables 
not
on primary key
-+-
 Reporter:  powderflask  |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  1.11
  (models, ORM)  |   Resolution:
 Severity:  Normal   |  worksforme
 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
-+-

Comment (by powderflask):

 This may have to do with one of the original models drawing data from a
 View - found this:
 " The feature of Postgres to be able to use the primary key of a table
 with GROUP BY and not need to add the other columns of that table in the
 GROUP BY clause is relatively new and works only for base tables. The
 optimizer is not (yet?) clever enough to identify primary keys for views,
 ctes or derived tables."
 https://dba.stackexchange.com/questions/88988/postgres-error-column-must-
 appear-in-the-group-by-clause-or-be-used-in-an-aggre

 I will try to reproduce this.

--
Ticket URL: 
Django 
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/069.40a9b8c735d3582d436a1674c4148c57%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-20 Thread Django
#28107: Can't perform annotation on related table when relation between tables 
not
on primary key
-+-
 Reporter:  powderflask  |Owner:  nobody
 Type:  Uncategorized|   Status:  closed
Component:  Database layer   |  Version:  1.11
  (models, ORM)  |   Resolution:
 Severity:  Normal   |  worksforme
 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:  new => closed
 * resolution:   => worksforme


Comment:

 I tried.  I cannot reproduce this with a simpler test case.  My original
 suspicion is completely wrong - it works just fine.

 I can only reproduce this in the insanely complex DB -- I will continue to
 try to track down the cause, but for now I'd say this issue is too
 undefined to work on.  Sorry for the trouble, I'm closing this for now.

--
Ticket URL: 
Django 
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/069.15aa678edcbaa190730cdf40d750a76b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-20 Thread Django
#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
-+-

Comment (by powderflask):

 The DB and relations are just nasty to set it all up.   I'm pretty sure I
 know what's needed to reproduce this -- I'll try to get something simpler
 to break in the same way, no sense in you banging your head against the
 ArcSDE wall.

 BTW - edge case is a very polite term for what this really is...   After
 writing this up, I decided to sacrifice the extra query to get the
 attachment.count() to buy a world of ponies.  My code base loves me for it

--
Ticket URL: 
Django 
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/069.fe0692ce58ca679a69949688fa11b85d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #28107: Can't perform annotation on related table when relation between tables not on primary key

2017-04-20 Thread Django
#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 Simon Charette):

 * cc: Simon Charette (added)


Comment:

 It's possible that's an edge case with the handling of `to_field`.

 Would it be possible for your to provide all the models involved in the
 queryset you're generating as it's really hard to figure out if the issue
 actually lies in the _GROUP BY_ logic without a set of models to reproduce
 the issue.

--
Ticket URL: 
Django 
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/069.d50b46520164c539e5c61f25492dc82d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.