Opened 14 years ago

Closed 13 years ago

#16316 closed Bug (duplicate)

Error with GenericRelation applied to a subclass

Reported by: jordanreiter@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I noticed this when using the django-threadedcomments app and trying to add a GenericRelation pointing to the ThreadedComment model. I would assume this holds true for any model that subclasses a model with generic foreign keys.

class Discussion(models.Model):
    title = models.CharField(max_length=100, help_text='Enter a descriptive title for this discussion.')
    content = models.TextField(null=True, blank=True)
    date = models.DateTimeField()
    comments = generic.GenericRelation(ThreadedComment)

And then

>>> Discussion.objects.filter(comments__isnull=False)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/path/to/django/db/models/query.py", line 69, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/path/to/django/db/models/query.py", line 84, in __len__
    self._result_cache.extend(self._iter)
  File "/path/to/django/db/models/query.py", line 273, in iterator
    for row in compiler.results_iter():
  File "/path/to/django/db/models/sql/compiler.py", line 680, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/path/to/django/db/models/sql/compiler.py", line 735, in execute_sql
    cursor.execute(sql, params)
  File "/path/to/django/db/backends/mysql/base.py", line 86, in execute
    return self.cursor.execute(query, args)
  File "/srv/python-environments/academicexperts/lib/python2.7/site-packages/MySQLdb/cursors.py", line 174, in execute
    self.errorhandler(self, exc, value)
  File "/srv/python-environments/academicexperts/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (1054, "Unknown column 'threadedcomments_comment.object_id' in 'on clause'")
>>> 

Change History (1)

comment:1 by Michael Manfre, 13 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #9899 (GenericRelation of a childmodel can't be used in lookup) and #12885 (GenericRelation fails to join the related table from a inherited model)

Note: See TracTickets for help on using tickets.
Back to Top