#31269: Generic Relations on multi table inheritance does not behave as other
fields
-----------------------------------------+------------------------
Reporter: Eduardo Klein | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.0
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 |
-----------------------------------------+------------------------
Suppose we have the following models:
{{{
#!python
class Tag(models.Model):
content_type = models.ForeignKey('contenttypes.ContentType',
on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
obj = GenericForeignKey()
class Point(models.Model):
name = models.CharField(max_length=256)
tags = GenericRelation("tag")
class SpecificPoint(Point):
pass
}}}
We create a specific_point instance as follow:
{{{
#!python
specific_point = SpecificPoint.objects.create(name="test")
}}}
Now we add a tag to the corresponding point instance :
{{{
#!python
point = Point.objects.get(pk=specific_point.id)
tag = point.tags.create()
}}}
When we do `specific_point.tags.all()` it returns en empty queryset,
instead of a queryset containing the tag instance that we have created and
that we would obtain doing `point.tags.all()`
I understand that the issue here is that the content_type associated with
the `tag` instance is the "point" one and not the "specificpoint", but
it's problematic since if we do `specific_point.pk` or
`specific_point.name` or any other field that is not a generic relation,
we would obtain exactly the same as `point.pk` or `point.name`, but the
"logic" is broken for generic relations.
I'm not sure that this is a bug, but at least I think it deserves some
consideration in the docs. If this is considered a bug, one possible
solution would be to concatenate the tags from both models' content_types.
--
Ticket URL: <https://code.djangoproject.com/ticket/31269>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.5a505835d8e3cfe79ad2eb3bd9862c26%40djangoproject.com.