0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Don't catch indexing errors for postgres search

This commit is contained in:
Karl Hobley 2020-07-21 17:42:01 +01:00 committed by Matt Westcott
parent 28b117a6bf
commit d90f20a71f
3 changed files with 19 additions and 2 deletions

View File

@ -299,6 +299,7 @@ class BaseSearchBackend:
autocomplete_query_compiler_class = None
results_class = None
rebuilder_class = None
catch_indexing_errors = False
def __init__(self, params):
pass

View File

@ -1006,6 +1006,7 @@ class Elasticsearch2SearchBackend(BaseSearchBackend):
mapping_class = Elasticsearch2Mapping
basic_rebuilder_class = ElasticsearchIndexRebuilder
atomic_rebuilder_class = ElasticsearchAtomicIndexRebuilder
catch_indexing_errors = True
settings = {
'settings': {

View File

@ -154,9 +154,19 @@ def insert_or_update_object(instance):
try:
backend.add(indexed_instance)
except Exception:
# Catch and log all errors
# Log all errors
logger.exception("Exception raised while adding %r into the '%s' search backend", indexed_instance, backend_name)
# Catch exceptions for backends that use an external service like Elasticsearch
# This is to prevent data loss if that external service was to go down and the user's
# save request was to fail.
# But note that we don't want this for database backends though as an error during a
# database transaction will require the transaction to be rolled back anyway. So If
# we caught the error here, the request will only crash again when the next database
# query is made but then the error message wouldn't be very informative.
if not backend.catch_indexing_errors:
raise
def remove_object(instance):
indexed_instance = get_indexed_instance(instance, check_exists=False)
@ -166,9 +176,14 @@ def remove_object(instance):
try:
backend.delete(indexed_instance)
except Exception:
# Catch and log all errors
# Log all errors
logger.exception("Exception raised while deleting %r from the '%s' search backend", indexed_instance, backend_name)
# Only catch the exception if the backend requires this
# See the comments in insert_or_update_object for an explanation
if not backend.catch_indexing_errors:
raise
class BaseField:
def __init__(self, field_name, **kwargs):