Opened 16 years ago
Closed 16 years ago
#8332 closed (duplicate)
delete generates faulty sql for subclasses of non-abstract parents
Reported by: | Daniel Bergey | Owned by: | Daniel Bergey |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Stack trace is attached.
Student is a subclass of Person. Person has a ForeignKey field pointing to Address. delete() calls the sql
UPDATE "tables_student" SET "address_id" = NULL WHERE "person_ptr_id" IN
Since address_id is a field of tables_person, this throws an exception.
Assuming CollectedObjects() is doing the right thing, the (a?) correct behavior would be to pass over address_id in line 836 of db/models/query.py (see below) when it shows up as a field of Student. After deleting the Student record, delete_objects will reach the related Person record, which has the real address_id field, set that to Null, and then delete the Address record.
The code I'm proposing changing:
831 del_query.delete_batch_related(pk_list) 832 833 update_query = sql.UpdateQuery(cls, connection) 834 for field in cls._meta.fields: 835 if field.rel and field.null and field.rel.to in seen_objs: 836 -> update_query.clear_related(field, pk_list)
I'm interested in testing the boundaries of this bug and writing a patch. I'm hoping someone can tell me if there's an easy way to test (line 835) whether field is local to cls or inherited from a parent.
Attachments (1)
Change History (3)
by , 16 years ago
comment:1 by , 16 years ago
Needs tests: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Found cls._meta.local_fields, which seems like just what I want in line 834. Probably won't have a chance to test before Monday.
(probably should have said in the original report that I'm using gentoo's SVN package; I'm not sure what revision it was built off of.)
comment:2 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
Looks like a duplicate of #7778
stack trace of error