On Sunday 26 February 2006 03:15, Russell Keith-Magee wrote: > Interesting... by way of diagnosis, it might be helpful to dump the > contents of seen_objs that is collected just before the call to > delete_objects() at line 216 of django/core/db/query.py. That > structure determines the order in which circular dependencies are > resolved; the error you are describing certainly sounds like a > circular dependency problem. > > Let me know if you have any luck narrowing the problem down at all.
Thanks for the tip, it sent me down the right road. But it was a long and winding round that led to this fix. Would you believe it if I told you that the following patch fixes it? --- django/db/models/loading.py (revision 2459) +++ django/db/models/loading.py (working copy) @@ -17,7 +17,7 @@ _app_list = [] for app_name in settings.INSTALLED_APPS: try: - _app_list.append(__import__(app_name + '.models', '', '', [''])) + _app_list.append(__import__(app_name + '.models', '', '', ['*'])) except ImportError, e: pass return _app_list @@ -26,7 +26,7 @@ "Returns the module containing the models for the given app_label." for app_name in settings.INSTALLED_APPS: if app_label == app_name.split('.')[-1]: - return __import__('%s.models' % app_name, '', '', ['']) + return __import__('%s.models' % app_name, '', '', ['*']) raise ImproperlyConfigured, "App with label %s could not be found" % app_label === (I mangled that patch a bit to make it fit, BTW) The existing usage of __import__ is a bit strange (with an empty string as the name to import), and seems to cause the problem. Basically those __import__ calls were somehow causing the model classes to get re-evaluated, rather than just imported, which eventually meant that this function failed: def get_all_related_objects(self): try: # Try the cache first. return self._all_related_objects except AttributeError: rel_objs = [] for klass in get_models(): for f in klass._meta.fields: if f.rel and self == f.rel.to._meta: rel_objs.append(RelatedObject(f.rel.to, klass, f)) self._all_related_objects = rel_objs return rel_objs The line: if f.rel and self == f.rel.to._meta: failed as the Options() instances did not have the same identity. Phew! That's a weird one! I'm guessing it's also to do with the fact that my models don't live in models.py. Would Adrian or Jacob or someone like to comment on the original usage of __import__ and whether this patch is OK? An alternative way to do the imports is this: __import__(app_name, '', '', ['models']).models and that also seems to work. One more thing: In the admin I'm not seeing the list of related objects to be deleted (but they are actually deleted). Is anyone else seeing this? If not there is another bug to track down. Luke -- The early bird gets the worm, but the second mouse gets the cheese. --Steven Wright Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---