Author: russellm Date: 2009-05-19 08:10:35 -0500 (Tue, 19 May 2009) New Revision: 10823
Modified: django/branches/releases/1.0.X/django/db/models/query.py django/branches/releases/1.0.X/tests/modeltests/delete/models.py Log: [1.0.X] Fixed #9308 -- Corrected the updated of nullable foreign key fields when deleting objects. Thanks to Bob Thomas for the fix, and markshep for the improvements on the test case. Merge of r10822 from trunk. Modified: django/branches/releases/1.0.X/django/db/models/query.py =================================================================== --- django/branches/releases/1.0.X/django/db/models/query.py 2009-05-19 12:44:17 UTC (rev 10822) +++ django/branches/releases/1.0.X/django/db/models/query.py 2009-05-19 13:10:35 UTC (rev 10823) @@ -867,7 +867,7 @@ update_query = sql.UpdateQuery(cls, connection) for field, model in cls._meta.get_fields_with_model(): if (field.rel and field.null and field.rel.to in seen_objs and - filter(lambda f: f.column == field.column, + filter(lambda f: f.column == field.rel.get_related_field().column, field.rel.to._meta.fields)): if model: sql.UpdateQuery(model, connection).clear_related(field, Modified: django/branches/releases/1.0.X/tests/modeltests/delete/models.py =================================================================== --- django/branches/releases/1.0.X/tests/modeltests/delete/models.py 2009-05-19 12:44:17 UTC (rev 10822) +++ django/branches/releases/1.0.X/tests/modeltests/delete/models.py 2009-05-19 13:10:35 UTC (rev 10823) @@ -30,7 +30,7 @@ # D -> A # So, we must delete Ds first of all, then Cs then Bs then As. -# However, if we start at As, we might find Bs first (in which +# However, if we start at As, we might find Bs first (in which # case things will be nice), or find Ds first. # Some mutually dependent models, but nullable @@ -96,7 +96,7 @@ >>> def clear_rel_obj_caches(models): ... for m in models: -... if hasattr(m._meta, '_related_objects_cache'): +... if hasattr(m._meta, '_related_objects_cache'): ... del m._meta._related_objects_cache # Nice order @@ -168,7 +168,16 @@ >>> o.keys() [<class 'modeltests.delete.models.F'>, <class 'modeltests.delete.models.E'>] +# temporarily replace the UpdateQuery class to verify that E.f is actually nulled out first +>>> import django.db.models.sql +>>> class LoggingUpdateQuery(django.db.models.sql.UpdateQuery): +... def clear_related(self, related_field, pk_list): +... print "CLEARING FIELD",related_field.name +... return super(LoggingUpdateQuery, self).clear_related(related_field, pk_list) +>>> original_class = django.db.models.sql.UpdateQuery +>>> django.db.models.sql.UpdateQuery = LoggingUpdateQuery >>> e1.delete() +CLEARING FIELD f >>> e2 = E() >>> e2.save() @@ -185,6 +194,9 @@ [<class 'modeltests.delete.models.F'>, <class 'modeltests.delete.models.E'>] >>> f2.delete() +CLEARING FIELD f +# Put this back to normal +>>> django.db.models.sql.UpdateQuery = original_class """ } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---