diff --git a/ckanext/harvest/logic/action/create.py b/ckanext/harvest/logic/action/create.py index 2a69235..042d8f6 100644 --- a/ckanext/harvest/logic/action/create.py +++ b/ckanext/harvest/logic/action/create.py @@ -165,7 +165,7 @@ def harvest_object_create(context, data_dict): obj = HarvestObject( guid=data.get('guid'), content=data.get('content'), - job=HarvestJob.get(data['job_id']), + job=data['job_id'], harvest_source_id=data.get('source_id'), package_id=data.get('package_id'), extras=[ HarvestObjectExtra(key=k, value=v) diff --git a/ckanext/harvest/logic/schema.py b/ckanext/harvest/logic/schema.py index 0500a5b..d303f95 100644 --- a/ckanext/harvest/logic/schema.py +++ b/ckanext/harvest/logic/schema.py @@ -21,7 +21,7 @@ from ckanext.harvest.logic.validators import (harvest_source_url_validator, dataset_type_exists, harvest_source_convert_from_config, harvest_source_id_exists, - harvest_job_id_exists, + harvest_job_exists, harvest_object_extras_validator, ) @@ -83,7 +83,7 @@ def harvest_object_create_schema(): 'guid': [ignore_missing, unicode], 'content': [ignore_missing, unicode], 'state': [ignore_missing, unicode], - 'job_id': [harvest_job_id_exists], + 'job_id': [harvest_job_exists], 'source_id': [ignore_missing, harvest_source_id_exists], 'package_id': [ignore_missing, package_id_exists], 'extras': [ignore_missing, harvest_object_extras_validator], diff --git a/ckanext/harvest/logic/validators.py b/ckanext/harvest/logic/validators.py index 9a4edb6..4dec758 100644 --- a/ckanext/harvest/logic/validators.py +++ b/ckanext/harvest/logic/validators.py @@ -22,13 +22,13 @@ def harvest_source_id_exists(value, context): raise Invalid('Harvest Source with id %r does not exist.' % str(value)) return value -def harvest_job_id_exists(value, context): - - result = HarvestJob.get(value,None) +def harvest_job_exists(value, context): + """Check if a harvest job exists and returns the model if it does""" + result = HarvestJob.get(value, None) if not result: raise Invalid('Harvest Job with id %r does not exist.' % str(value)) - return value + return result def _normalize_url(url): o = urlparse.urlparse(url)