#22982 closed Bug (fixed)
Coercing GenericRelation property to string raises StopIteration exception
Reported by: | Ben Davis | Owned by: | nobody |
---|---|---|---|
Component: | contrib.contenttypes | Version: | 1.7-rc-1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
For example,
class TaggedItem(models.Model): tag = models.SlugField() content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') class Bookmark(models.Model): url = models.URLField() tags = GenericRelation(TaggedItem) {{{ #!python >>> b = Bookmark.objects.create(url='https://www.djangoproject.com/') >>> str(b.tags) Traceback (most recent call last): File "<console>", line 1, in <module> File "django/db/models/manager.py", line 81, in __str__ in opts.concrete_managers + opts.abstract_managers StopIteration }}}
Change History (6)
comment:1 by , 10 years ago
Easy pickings: | unset |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 10 years ago
I believe so. The bug occurs in stable/1.7.x, and it seems the code for Manager.__str__
was added here: https://github.com/django/django/commit/d818e0c9#diff-bf776a3b8e5dbfac2432015825ef8afeR166
comment:3 by , 10 years ago
A little more detail: A GenericRelation attribute is a descriptor that returns a dynamically created Manager. Since Manager.contribute_to_class
is not called during this process, it does not get added to the model's concrete_managers
or abstract_managers
.
I guess the question at this point is whether or not it should be included as an abstract/concrete manager, or if the __str__
method should simply catch StopIteration and return repr(self)
as a fallback.
comment:4 by , 10 years ago
I've put up a pull request here https://github.com/django/django/pull/3030
comment:5 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Do you know if it's a regression in 1.7?