#9899: GenericRelation of a childmodel can't be used in lookup
-------------------------------------+-------------------------------------
Reporter: miracle2k | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 1.0
(models, ORM) |
Severity: Normal | Resolution: fixed
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 timgraham):
* status: new => closed
* resolution: => fixed
Old description:
> {{{
> class Feature(models.Model):
> object_id = models.PositiveIntegerField()
> content_type = models.ForeignKey(ContentType)
> content_object = GenericForeignKey()
> is_public = models.BooleanField()
>
> class Base(models.Model):
> pass
>
> class Child(models.Model):
> features = GenericRelation(Feature)
> }}}
>
> {{{
> >>> Child.objects.filter(features__ispublic=False).count()
> <class '_mysql_exceptions.OperationalError'>: (1054, "Unknown column
> 'app_feature.base_ptr_id' in 'where clause'")
> }}}
>
> The query that is executed:
>
> {{{
> SELECT COUNT(*) FROM `app_child` INNER JOIN `app_feature` ON
> (`app_child`.`feed_ptr_id` = `app_feature`.`object_id`) INNER JOIN
> `app_feature` T4 ON (`app_feature`.`feed_ptr_id` = T4.`id`) WHERE
> (`app_feature`.`feed_ptr_id` IS NOT NULL AND T4.`content_type_id` = %s )
> }}}
New description:
{{{
class Feature(models.Model):
object_id = models.PositiveIntegerField()
content_type = models.ForeignKey(ContentType)
content_object = GenericForeignKey()
is_public = models.BooleanField()
class Base(models.Model):
pass
class Child(models.Model):
features = GenericRelation(Feature)
}}}
{{{
>>> Child.objects.filter(features__is_public=False).count()
<class '_mysql_exceptions.OperationalError'>: (1054, "Unknown column
'app_feature.base_ptr_id' in 'where clause'")
}}}
The query that is executed:
{{{
SELECT COUNT(*) FROM `app_child` INNER JOIN `app_feature` ON
(`app_child`.`feed_ptr_id` = `app_feature`.`object_id`) INNER JOIN
`app_feature` T4 ON (`app_feature`.`feed_ptr_id` = T4.`id`) WHERE
(`app_feature`.`feed_ptr_id` IS NOT NULL AND T4.`content_type_id` = %s )
}}}
--
Comment:
I couldn't reproduce as far back as 1.4, so I guess this has been fixed
between 1.0 and then.
--
Ticket URL: <https://code.djangoproject.com/ticket/9899#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 [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/067.7ed5a25bb892a849fcb5787447268f9c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.