Don't check whether the object exists when deleting it from search index

Fixes #2594
pull/2407/merge
Karl Hobley 2016-05-18 13:26:58 +01:00 zatwierdzone przez Matt Westcott
rodzic 7465e2eb91
commit dc6f09ba40
2 zmienionych plików z 3 dodań i 5 usunięć

Wyświetl plik

@ -99,13 +99,13 @@ def class_is_indexed(cls):
return issubclass(cls, Indexed) and issubclass(cls, models.Model) and not cls._meta.abstract return issubclass(cls, Indexed) and issubclass(cls, models.Model) and not cls._meta.abstract
def get_indexed_instance(instance): def get_indexed_instance(instance, check_exists=True):
indexed_instance = instance.get_indexed_instance() indexed_instance = instance.get_indexed_instance()
if indexed_instance is None: if indexed_instance is None:
return return
# Make sure that the instance is in its class's indexed objects # Make sure that the instance is in its class's indexed objects
if not type(indexed_instance).get_indexed_objects().filter(pk=indexed_instance.pk).exists(): if check_exists and not type(indexed_instance).get_indexed_objects().filter(pk=indexed_instance.pk).exists():
return return
return indexed_instance return indexed_instance
@ -124,7 +124,7 @@ def insert_or_update_object(instance):
def remove_object(instance): def remove_object(instance):
indexed_instance = get_indexed_instance(instance) indexed_instance = get_indexed_instance(instance, check_exists=False)
if indexed_instance: if indexed_instance:
for backend_name, backend in get_search_backends_with_name(with_auto_update=True): for backend_name, backend in get_search_backends_with_name(with_auto_update=True):

Wyświetl plik

@ -1,7 +1,6 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
import mock import mock
import unittest
from django.test import TestCase, override_settings from django.test import TestCase, override_settings
@ -104,7 +103,6 @@ class TestRemoveObject(TestCase):
backend().add.assert_called_with(obj) backend().add.assert_called_with(obj)
@unittest.expectedFailure
def test_removes_unsaved_object(self, backend): def test_removes_unsaved_object(self, backend):
obj = models.SearchTest(title="Test") obj = models.SearchTest(title="Test")
index.remove_object(obj) index.remove_object(obj)