Skip to content

Commit

Permalink
raise error and return None for ParentNotHarvestedException
Browse files Browse the repository at this point in the history
  • Loading branch information
FuhuXia committed Jun 25, 2024
1 parent 3506258 commit ae71b3e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions ckanext/datajson/datajson.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ckan.lib.navl.validators import ignore_empty, unicode_only
from ckan.lib.search import rebuild

from ckanext.harvest.model import HarvestObject, HarvestObjectError, HarvestObjectExtra
from ckanext.harvest.model import HarvestObject, HarvestObjectExtra
from ckanext.harvest.harvesters.base import HarvesterBase
from ckanext.datajson.exceptions import ParentNotHarvestedException
import uuid
Expand Down Expand Up @@ -458,14 +458,7 @@ def is_part_of_to_package_id(self, ipo, harvest_object):
# we have 0 o bad results
msg = 'Parent identifier not found: "{}"'.format(ipo)
log.error(msg)
try:
harvest_object_error = HarvestObjectError(message=msg, object=harvest_object)
harvest_object_error.save()
harvest_object.state = "ERROR"
harvest_object.save()
except Exception:
pass
raise ParentNotHarvestedException('Unable to find parent dataset. Raising error to allow re-run later')
raise ParentNotHarvestedException('Unable to find parent dataset.')

def import_stage(self, harvest_object):
# The import stage actually creates the dataset.
Expand Down Expand Up @@ -501,7 +494,11 @@ def import_stage(self, harvest_object):

# check if parent is already harvested
parent_identifier = parent_pkg_id.replace('IPO:', '')
parent = self.is_part_of_to_package_id(parent_identifier, harvest_object)
try:
parent = self.is_part_of_to_package_id(parent_identifier, harvest_object)
except ParentNotHarvestedException as e:
self._save_object_error(str(e), harvest_object, 'Import')
return None
parent_pkg_id = parent['id']

if extra.key.startswith('catalog_'):
Expand Down

0 comments on commit ae71b3e

Please sign in to comment.