Opened 14 years ago

Closed 14 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


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/ (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)
833             update_query = sql.UpdateQuery(cls, connection)
834             for field in cls._meta.fields:
835                 if field.rel and field.null and 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)

trace (993 bytes) - added by Daniel Bergey 14 years ago.
stack trace of error

Download all attachments as: .zip

Change History (3)

Changed 14 years ago by Daniel Bergey

Attachment: trace added

stack trace of error

comment:1 Changed 14 years ago by Daniel Bergey

Needs tests: set
Owner: changed from nobody to Daniel Bergey
Status: newassigned

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 Changed 14 years ago by Bob Thomas

Resolution: duplicate
Status: assignedclosed

Looks like a duplicate of #7778

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