Skip to content

Commit

Permalink
Merge pull request #2623 from ckan/notification-errors
Browse files Browse the repository at this point in the history
Stop reraising exceptions caused by notifications.
  • Loading branch information
rossjones committed Sep 8, 2015
2 parents 8f7caa5 + f19705d commit b47721a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions ckan/model/modification.py
@@ -1,5 +1,7 @@
import logging

from ckan.lib.search import SearchIndexError

import ckan.plugins as plugins
import domain_object
import package as _package
Expand All @@ -9,6 +11,7 @@

__all__ = ['DomainObjectModificationExtension']


class DomainObjectModificationExtension(plugins.SingletonPlugin):
"""
A domain object level interface to change notifications
Expand All @@ -30,7 +33,6 @@ def notify_observers(self, func):
plugins.IDomainObjectModification):
func(observer)


def before_commit(self, session):
self.notify_observers(session, self.notify)

Expand Down Expand Up @@ -60,7 +62,8 @@ def notify_observers(self, session, method):
for item in plugins.PluginImplementations(plugins.IResourceUrlChange):
item.notify(obj)

changed_pkgs = set(obj for obj in changed if isinstance(obj, _package.Package))
changed_pkgs = set(obj for obj in changed
if isinstance(obj, _package.Package))

for obj in new | changed | deleted:
if not isinstance(obj, _package.Package):
Expand All @@ -76,25 +79,24 @@ def notify_observers(self, session, method):
for obj in changed_pkgs:
method(obj, domain_object.DomainObjectOperation.changed)


def notify(self, entity, operation):
for observer in plugins.PluginImplementations(
plugins.IDomainObjectModification):
try:
observer.notify(entity, operation)
except SearchIndexError, search_error:
log.exception(search_error)
raise search_error
except Exception, ex:
log.exception(ex)
# We reraise all exceptions so they are obvious there
# is something wrong
raise

def notify_after_commit(self, entity, operation):
for observer in plugins.PluginImplementations(
plugins.IDomainObjectModification):
try:
observer.notify_after_commit(entity, operation)
except SearchIndexError, search_error:
log.exception(search_error)
raise search_error
except Exception, ex:
log.exception(ex)
# We reraise all exceptions so they are obvious there
# is something wrong
raise

0 comments on commit b47721a

Please sign in to comment.