Commit d95fa1dd authored by Roberto Rosario's avatar Roberto Rosario
Browse files

Add debug information for GitLab issue #913


Signed-off-by: Roberto Rosario's avatarRoberto Rosario <roberto.rosario@mayan-edms.com>
parent 984d8d29
Pipeline #254692683 skipped with stage
......@@ -163,7 +163,7 @@ class WhooshSearchBackend(SearchBackend):
raise
else:
try:
# Use a shadow method to allow using a single lock for
# Use a private method to allow using a single lock for
# all recursions.
self._index_instance(
instance=instance, exclude_set=exclude_set
......@@ -175,7 +175,7 @@ class WhooshSearchBackend(SearchBackend):
if not exclude_set:
exclude_set = set()
# Avoid infite recursion
# Avoid infinite recursion.
if instance in exclude_set:
return
......@@ -198,8 +198,18 @@ class WhooshSearchBackend(SearchBackend):
field_map=self.get_resolved_field_map(search_model=search_model), instance=instance
)
writer.delete_by_term('id', str(instance.pk))
writer.add_document(**kwargs)
writer.commit()
try:
writer.add_document(**kwargs)
writer.commit()
except Exception as exception:
logger.error(
'Unexpected exception while indexing object id: %s, '
'search model: %s, index data: %s, raw data: %s, '
'field map: %s', search_model.get_full_name(),
instance.pk, kwargs, instance.__dict__,
self.get_resolved_field_map(search_model=search_model)
)
raise
for field_class in instance._meta.get_fields():
# Only to recursive indexing for related models that are
......
......@@ -11,7 +11,10 @@ from .literals import TASK_RETRY_DELAY
logger = logging.getLogger(name=__name__)
@app.task(bind=True, default_retry_delay=TASK_RETRY_DELAY, max_retries=None, ignore_result=True)
@app.task(
bind=True, default_retry_delay=TASK_RETRY_DELAY, max_retries=None,
ignore_result=True
)
def task_deindex_instance(self, app_label, model_name, object_id):
logger.info('Executing')
......@@ -26,7 +29,10 @@ def task_deindex_instance(self, app_label, model_name, object_id):
logger.info('Finished')
@app.task(bind=True, default_retry_delay=TASK_RETRY_DELAY, max_retries=None, ignore_result=True)
@app.task(
bind=True, default_retry_delay=TASK_RETRY_DELAY, max_retries=None,
ignore_result=True
)
def task_index_search_model(self, search_model_full_name):
search_model = SearchModel.get(name=search_model_full_name)
......@@ -40,14 +46,20 @@ def task_index_search_model(self, search_model_full_name):
)
@app.task(bind=True, default_retry_delay=TASK_RETRY_DELAY, max_retries=None, ignore_result=True)
@app.task(
bind=True, default_retry_delay=TASK_RETRY_DELAY, max_retries=None,
ignore_result=True
)
def task_index_instance(self, app_label, model_name, object_id):
logger.info('Executing')
try:
Model = apps.get_model(app_label=app_label, model_name=model_name)
except LookupError:
"""Non fatal, just exit the task."""
"""
The app or model does not exists anymore. Non fatal, just exit
the task.
"""
else:
try:
instance = Model._meta.default_manager.get(pk=object_id)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment