[Django] #25122: GenericRelation with a string argument will raise an AttributeError when accessed.

20 views
Skip to first unread message

Django

unread,
Jul 13, 2015, 7:28:13 PM7/13/15
to django-...@googlegroups.com
#25122: GenericRelation with a string argument will raise an AttributeError when
accessed.
-------------------------------------+-------------------------------------
Reporter: martin-c | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.8
contrib.contenttypes | Keywords: GenericRelation,
Severity: Normal | AttributeError
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
In other relationship fields it is possible to specify the target model by
passing its model name as a string, such as
{{{
#!python
class Car(models.Model):
manufacturer = models.ForeignKey('production.Manufacturer')
}}}
However, in the case of a GenericRelation,
{{{
#!python
class Car(models.Model):
manufacturers = GenericRelation('production.Manufacturer')
}}}
accessing the manufacturers field will cause a AttributeError to be
raised.
{{{
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/.../.python-env/lib/python2.7/site-
packages/django/contrib/contenttypes/fields.py", line 406, in __get__
superclass = rel_model._default_manager.__class__
AttributeError: 'unicode' object has no attribute '_default_manager'
}}}
So it seems only the target class instance can be passed to
GenericRelation().

--
Ticket URL: <https://code.djangoproject.com/ticket/25122>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 14, 2015, 7:44:00 AM7/14/15
to django-...@googlegroups.com
#25122: GenericRelation with a string argument will raise an AttributeError when
accessed.
-------------------------------------+-------------------------------------
Reporter: martin-c | Owner: nobody
Type: Bug | Status: closed
Component: | Version: 1.8
contrib.contenttypes | Resolution:
Severity: Normal | worksforme
Keywords: GenericRelation, | Triage Stage:
AttributeError | Unreviewed
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
* needs_better_patch: => 0
* resolution: => worksforme
* needs_tests: => 0
* needs_docs: => 0


Comment:

I had no trouble using strings in a test project and there are several
string references inside a `GenericRelation` in Django's test suite.
Please reopen if you can provide a minimal project to reproduce.

--
Ticket URL: <https://code.djangoproject.com/ticket/25122#comment:1>

Reply all
Reply to author
Forward
0 new messages