Ticket #9308: 9308-b.diff

File 9308-b.diff, 1.8 KB (added by markshep, 10 years ago)

use subclassing instead of monkey patching

  • django/db/models/query.py

     
    10071007            update_query = sql.UpdateQuery(cls, connection)
    10081008            for field, model in cls._meta.get_fields_with_model():
    10091009                if (field.rel and field.null and field.rel.to in seen_objs and
    1010                         filter(lambda f: f.column == field.column,
     1010                        filter(lambda f: f.column == field.rel.get_related_field().column,
    10111011                        field.rel.to._meta.fields)):
    10121012                    if model:
    10131013                        sql.UpdateQuery(model, connection).clear_related(field,
  • tests/modeltests/delete/models.py

     
    168168>>> o.keys()
    169169[<class 'modeltests.delete.models.F'>, <class 'modeltests.delete.models.E'>]
    170170
     171# temporarily replace the UpdateQuery class to verify that E.f is actually nulled out first
     172>>> import django.db.models.sql
     173>>> class PatchedUpdateQuery(django.db.models.sql.UpdateQuery):
     174...     def clear_related(self, related_field, pk_list):
     175...         print related_field.name
     176...         return super(PatchedUpdateQuery, self).clear_related(related_field, pk_list)
     177>>> original_class = django.db.models.sql.UpdateQuery
     178>>> django.db.models.sql.UpdateQuery = PatchedUpdateQuery
    171179>>> e1.delete()
     180f
    172181
    173182>>> e2 = E()
    174183>>> e2.save()
     
    185194[<class 'modeltests.delete.models.F'>, <class 'modeltests.delete.models.E'>]
    186195
    187196>>> f2.delete()
     197f
    188198
     199# Put this back to normal
     200>>> django.db.models.sql.UpdateQuery = original_class
    189201"""
    190202}
Back to Top