[Django] #28988: Multi-table inheritance breaks GenericRelation querying

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
#28988: Multi-table inheritance breaks GenericRelation querying
-----------------------------------------+------------------------
               Reporter:  robwa          |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  Uncategorized  |        Version:  1.11
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 Minimal example to reproduce. Create two models:

 {{{
 #!python
 class Generic(models.Model):
     content_type = models.ForeignKey('contenttypes.ContentType')
     object_id = models.PositiveIntegerField()
     obj = GenericForeignKey()

 class Vehicle(models.Model):
     associations = GenericRelation('Generic',
 related_query_name='vehicles')
 }}}

 Create a `Vehicle` and a `Generic` object pointing to the `Vehicle`. The
 following query returns the expected result:

 {{{
 In [2]: Generic.objects.filter(vehicles__id=1)
 Out[2]: <QuerySet [<Generic: Generic object>]>
 }}}

 Add a third model. Don't change any data. Now the query returns an empty
 query set:

 {{{
 #!python
 class Bike(Vehicle):
     pass
 }}}

 {{{
 In [2]: Generic.objects.filter(vehicles__id=1)
 Out[2]: <QuerySet []>
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28988>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/048.6f6259f40c799c69178c11f79f5b5d19%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  nobody
         Type:  Bug                   |                   Status:  new
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

 * type:  Uncategorized => Bug
 * component:  Uncategorized => contrib.contenttypes
 * stage:  Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/28988#comment:1>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.6a31a77a41cfcd9f55e60ab58448ba9e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  Paulo
         Type:  Bug                   |                   Status:  assigned
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Paulo):

 * owner:  nobody => Paulo
 * status:  new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28988#comment:2>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.7142fa4c8b5497ddd6144657491ba3cc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  Paulo
         Type:  Bug                   |                   Status:  assigned
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by robwa):

 I'm not sure if this is helpful, but I found

 {{{
 In [44]: Generic._meta.get_field('vehicles').field.model
 Out[44]: foo.models.Bike
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28988#comment:3>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.7a141399b3a27df6c1e154407a9079ac%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  Paulo
         Type:  Bug                   |                   Status:  assigned
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by robwa):

 Now I can see why this happens:

 * `GenericRelation` fields are created as ''private fields''.
 * ''Private fields'' are explicitly inherited by child classes
 ([https://github.com/django/django/blob/649d5eaa8b7b224fc0eb8a3339a589288d5b10e8/django/db/models/base.py#L290
 db.models.base]).
 * When constructing the relation tree, ''private fields'' are included
 ([https://github.com/django/django/blob/649d5eaa8b7b224fc0eb8a3339a589288d5b10e8/django/db/models/options.py#L858
 db.models.options]).
 * When constructing the fields map, relations to ''private fields'' of
 child classes simply overwrite the relations to the parents
 ([https://github.com/django/django/blob/649d5eaa8b7b224fc0eb8a3339a589288d5b10e8/django/db/models/options.py#L586
 db.models.options]).

 Where is the point to fix this?

--
Ticket URL: <https://code.djangoproject.com/ticket/28988#comment:4>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.ba2a9d5544aca6444f3b6553e9912acb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  Paulo
         Type:  Bug                   |                   Status:  assigned
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by robwa):

 Maybe the ''reverse relationship'' should be removed from
 `GenericRelation`s when copying them to child classes.

--
Ticket URL: <https://code.djangoproject.com/ticket/28988#comment:5>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.c1cba706220820b520e8f8b71677d336%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  Paulo
         Type:  Bug                   |                   Status:  assigned
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by Paulo):

 I think the behavior should be consistent with how a normal ForeignKey
 field behaves in multi-table inheritance.
 In the following scenario:


 {{{
 class Car(models.Model):
     owner = models.ForeignKey(Owner, related_name='cars')
     some_id = models.CharField(max_length=100)

 class Car2(Car):
     pass
 }}}


 Running
 {{{
 Owner.objects.filter(cars__isnull=True)
 }}}


 Will output:

 {{{
 SELECT "paulotest_owner"."id",
        "paulotest_owner"."nick"
 FROM "paulotest_owner"
 LEFT OUTER JOIN "paulotest_car" ON ("paulotest_owner"."id" =
 "paulotest_car"."owner_id")
 WHERE "paulotest_car"."id" IS NULL
 }}}

 So we should prevent the reverse relationship from being set.

 @Robert, if you would like to work on this, I can un-assign it, I'm
 planning to tackle it within the next two weeks.

--
Ticket URL: <https://code.djangoproject.com/ticket/28988#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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.8ec4532641f36e2c1555692467a8192f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  robwa
         Type:  Bug                   |                   Status:  assigned
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by robwa):

 * owner:  Paulo => robwa


Comment:

 @Paulo, I will try to work on this. If I come up with a patch, I'd like to
 discuss it with you, as I'm not very familiar with the django model
 internals.

--
Ticket URL: <https://code.djangoproject.com/ticket/28988#comment:7>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.238a6996967995bca8941cb25a54c1b3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  robwa
         Type:  Bug                   |                   Status:  assigned
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by robwa):

 * has_patch:  0 => 1


Comment:

 Added a [https://github.com/django/django/pull/9624 pull request].

--
Ticket URL: <https://code.djangoproject.com/ticket/28988#comment:8>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.ed1dd69abdb468646870602c8341b5ba%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  robwa
         Type:  Bug                   |                   Status:  assigned
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  1
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Carlton Gibson):

 * needs_better_patch:  0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/28988#comment:9>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.d9049a9954bfbf64468fafdd5e5e3200%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  (none)
         Type:  Bug                   |                   Status:  new
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  1
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by robwa):

 * owner:  robwa => (none)
 * status:  assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/28988#comment:10>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.7ff09b285b8da635654f74bd77385bfa%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
--------------------------------------+------------------------------------
     Reporter:  robwa                 |                    Owner:  (none)
         Type:  Bug                   |                   Status:  new
    Component:  contrib.contenttypes  |                  Version:  1.11
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  1
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by robwa):

 Updated the [https://github.com/django/django/pull/9624 PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/28988#comment:11>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.5afce9327456f8ad944b44240310631f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
-------------------------------------+-------------------------------------
     Reporter:  robwa                |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:                       |                  Version:  1.11
  contrib.contenttypes               |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Ready for
                                     |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

 * needs_better_patch:  1 => 0
 * stage:  Accepted => Ready for checkin


Comment:

 Updated changes look good.

--
Ticket URL: <https://code.djangoproject.com/ticket/28988#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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.8a94dc78d7d7587dfb0874ae7f6df4f4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28988: Multi-table inheritance breaks GenericRelation querying

Django
In reply to this post by Django
#28988: Multi-table inheritance breaks GenericRelation querying
-------------------------------------+-------------------------------------
     Reporter:  robwa                |                    Owner:  Tim
                                     |  Graham <timograham@…>
         Type:  Bug                  |                   Status:  closed
    Component:                       |                  Version:  1.11
  contrib.contenttypes               |
     Severity:  Normal               |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Ready for
                                     |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

 * status:  new => closed
 * owner:  (none) => Tim Graham <timograham@…>
 * resolution:   => fixed


Comment:

 In [changeset:"4ab027b94409e6415b774797bf9d3593da9d9ea8" 4ab027b]:
 {{{
 #!CommitTicketReference repository=""
 revision="4ab027b94409e6415b774797bf9d3593da9d9ea8"
 Fixed #28988 -- Fixed queries when a GenericRelation is used with multi-
 table inheritance.
 }}}

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