﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8332	delete generates faulty sql for subclasses of non-abstract parents	Daniel Bergey	Daniel Bergey	"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."		closed	Uncategorized	dev		duplicate			Unreviewed	0	0	1	0	0	0
