﻿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
16648	Router unable to delete relationships spanning multiple DBs	chadlyon	nobody	"The following method in django.db.models.Model has a deficiency such that if you define a router that uses _meta info to determine where to write and your model objects have Fkey dependencies spanning the multiple DBs then you get an integrity error because this method assumes a single DB when collecting dependent objects to delete:

{{{
#!python
def delete(self, using=None):
        using = using or router.db_for_write(self.__class__, instance=self)
        assert self._get_pk_val() is not None, ""%s object can't be deleted because its %s attribute is set to None."" % (self._meta.object_name, self._meta.pk.attname)

        # Find all the objects than need to be deleted.
        seen_objs = CollectedObjects()
        self._collect_sub_objects(seen_objs)

        # Actually delete the objects.
        delete_objects(seen_objs, using)
}}}

Basically, router.db_for_write(…) should be called inside delete_objects(…) for each seen_objs

You can work around this by overriding delete(...) for your models but I think this should be fixed in base.
"	Bug	closed	Database layer (models, ORM)	1.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
