Opened 16 years ago

Last modified 13 years ago

#7853 closed

Problem with model inheritance when parent has relation to self — at Version 5

Reported by: osanha@… Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: model inheritance
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Russell Keith-Magee)

Test models:

class Parent(models.Model):
    s = models.ForeignKey('self', null=True, blank=True)
    a = models.TextField()
    
class Child(Parent):
    b = models.TextField()

Test session:

>>> child = Child.objects.create(a='parent field', b='child field')
>>> child.delete()
Traceback (most recent call last):
...
ProgrammingError:  "s_id" column is not exist at "forums_child" relation.

These error was begined at 0.97-pre-SVN-8007
as I know, previous version is not shown these errors.

Change History (6)

comment:1 by Sanha, 16 years ago

Is it related with 'newforms-admin' ?
http://code.djangoproject.com/changeset/7964

comment:2 by Russell Keith-Magee, 16 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #6755.

comment:3 by Sanha, 16 years ago

Component: django-admin.pyDatabase wrapper
Keywords: django admin removed
Resolution: duplicate
Status: closedreopened

I think that second issue is valid.

when parent model has foreign key to self, delete child (or parent) object was failed because finding parent's foreign key.

see below.

class Parent(models.Model):
    s = models.ForeignKey('self', null=True, blank=True)
# or same:  s = models.ForeignKey('Parent', null=True, blank=True)
    a = models.TextField()
    
class Child(Parent):
    b = models.TextField()

python shell

>>> child = Child.objects.create(a='parent field', b='child field')
>>> child.delete()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib64/python2.5/site-packages/django/db/models/base.py", line 423, in delete
    delete_objects(seen_objs)
  File "/usr/lib64/python2.5/site-packages/django/db/models/query.py", line 836, in delete_objects
    update_query.clear_related(field, pk_list)
  File "/usr/lib64/python2.5/site-packages/django/db/models/sql/subqueries.py", line 211, in clear_related
    self.execute_sql(None)
  File "/usr/lib64/python2.5/site-packages/django/db/models/sql/subqueries.py", line 112, in execute_sql
    super(UpdateQuery, self).execute_sql(result_type)
  File "/usr/lib64/python2.5/site-packages/django/db/models/sql/query.py", line 1608, in execute_sql
    cursor.execute(sql, params)
  File "/usr/lib64/python2.5/site-packages/django/db/backends/util.py", line 18, in execute
    return self.cursor.execute(sql, params)
ProgrammingError:  "s_id" column is not exist at "forums_child" relation.

comment:4 by charmless, 16 years ago

Resolution: duplicate
Status: reopenedclosed

Marking a ticket as a Duplicate means the problem is known and being worked on at another ticket. It is not meant to imply that a problem isn't valid (if it were, the duplicate would be closed too :) )

For browsers: Duplicate of #6755.

in reply to:  4 comment:5 by Russell Keith-Magee, 16 years ago

Description: modified (diff)
milestone: 1.0 beta
Resolution: duplicate
Status: closedreopened
Summary: django admin problem used model inheritanceProblem with model inheritance when parent has relation to self

Replying to charmless:

Marking a ticket as a Duplicate means the problem is known and being worked on at another ticket. It is not meant to imply that a problem isn't valid (if it were, the duplicate would be closed too :) )

In this case, it looks like the reporter has put two issues in a single ticket (which, by the way, is very bad form). The first issue (inheritance doesn't work in admin) is clearly a duplicate of #6755. The second part of the report isn't obviously a duplicate, so it requires independent verification.

I've updated the ticket title and description to describe the problem better.

by Russell Keith-Magee, 16 years ago

Attachment: 7853-r8016-tests.diff added

Test case demonstrating problem

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