def clean_orphan_obj_perms():
 from guardian.models import UserObjectPermission
 from guardian.models import GroupObjectPermission
 deleted = 0
 for perm in chain(UserObjectPermission.objects.all().iterator(), GroupObjectPermission.objects.all().iterator()):
  if (perm.content_object is None):
   logger.debug((u'Removing %s (pk=%d)' % (perm, perm.pk)))
   perm.delete()
   deleted += 1
 logger.info((u'Total removed orphan object permissions instances: %d' % deleted))
 return deleted

def clean_orphan_obj_perms ( ) : from guardian . models import UserObjectPermission from guardian . models import GroupObjectPermission deleted = 0 for perm in chain ( UserObjectPermission . objects . all ( ) . iterator ( ) , GroupObjectPermission . objects . all ( ) . iterator ( ) ) : if ( perm . content_object is None ) : logger . debug ( ( u'Removing %s (pk=%d)' % ( perm , perm . pk ) ) ) perm . delete ( ) deleted += 1 logger . info ( ( u'Total removed orphan object permissions instances: %d' % deleted ) ) return deleted
seeks and removes all object permissions entries pointing at non-existing targets .