From cb8b8082747588a9c47ef800e37fe8a65a9ff1d4 Mon Sep 17 00:00:00 2001 From: joetsoi Date: Fri, 29 Mar 2013 00:59:20 +0000 Subject: [PATCH 1/3] sanity check that harvest source id matches harvest dataset id remove author_email, license_id, maintainer_email, maintainer and author from pacakge_dict, these were not actually necessary --- ckanext/harvest/model/__init__.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ckanext/harvest/model/__init__.py b/ckanext/harvest/model/__init__.py index 4830be4..6539d64 100644 --- a/ckanext/harvest/model/__init__.py +++ b/ckanext/harvest/model/__init__.py @@ -407,6 +407,13 @@ ALTER TABLE harvest_object_error Session.commit() log.info('Harvest tables migrated to v3') +class PackageIdHarvestSourceIdMismatch(Exception): + """ + The package created for the harvest source must match the id of the + harvest source + """ + pass + def migrate_v3_create_datasets(): import pylons from paste.registry import Registry @@ -465,15 +472,15 @@ def migrate_v3_create_datasets(): 'source_type': source.type, 'config': source.config, 'frequency': source.frequency, - 'author_email': '', - 'license_id': '', - 'maintainer_email': '', - 'maintainer': '', - 'author': '' } context['message'] = 'Created package for harvest source {0}'.format(source.id) try: - logic.get_action('package_create')(context, package_dict) + new_package_id = logic.get_action('package_create')(context, package_dict) + if new_package_id != source.id or not context['return_id_only']: + # this check only makes sense if we are sure we are returning + # the package id not the package object + raise PackageIdHarvestSourceIdMismatch + log.info('Created new package for source {0} ({1})'.format(source.id, source.url)) except logic.ValidationError,e: log.error('Validation Error: %s' % str(e.error_summary)) From 3ac065f0f095a226e7e404e50646f087f311724f Mon Sep 17 00:00:00 2001 From: joetsoi Date: Fri, 29 Mar 2013 01:17:24 +0000 Subject: [PATCH 2/3] fix package_schema import --- ckanext/harvest/harvesters/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/harvest/harvesters/base.py b/ckanext/harvest/harvesters/base.py index 0960a38..0214050 100644 --- a/ckanext/harvest/harvesters/base.py +++ b/ckanext/harvest/harvesters/base.py @@ -10,7 +10,7 @@ from ckan import model from ckan.model import Session, Package from ckan.logic import ValidationError, NotFound, get_action -from ckan.logic.schema import default_package_schema +from ckan.logic.schema import default_create_package_schema from ckan.lib.navl.validators import ignore_missing,ignore from ckan.lib.munge import munge_title_to_name,substitute_ascii_equivalents From 66ff773f9945cb76a286cd4baf79e414ce3cdf1a Mon Sep 17 00:00:00 2001 From: joetsoi Date: Fri, 29 Mar 2013 12:47:14 +0000 Subject: [PATCH 3/3] remove previous commit import --- ckanext/harvest/harvesters/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/harvest/harvesters/base.py b/ckanext/harvest/harvesters/base.py index 0214050..0960a38 100644 --- a/ckanext/harvest/harvesters/base.py +++ b/ckanext/harvest/harvesters/base.py @@ -10,7 +10,7 @@ from ckan import model from ckan.model import Session, Package from ckan.logic import ValidationError, NotFound, get_action -from ckan.logic.schema import default_create_package_schema +from ckan.logic.schema import default_package_schema from ckan.lib.navl.validators import ignore_missing,ignore from ckan.lib.munge import munge_title_to_name,substitute_ascii_equivalents