From 8b5d70c6fe83fd73a6ae518664f5f0e2ff126314 Mon Sep 17 00:00:00 2001 From: Stefan Oderbolz Date: Fri, 11 Oct 2013 18:08:32 +0200 Subject: [PATCH] Only try to create/match a organization if there is a remote_org --- ckanext/harvest/harvesters/ckanharvester.py | 35 +++++++++++---------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/ckanext/harvest/harvesters/ckanharvester.py b/ckanext/harvest/harvesters/ckanharvester.py index b08fe1d..884bd19 100644 --- a/ckanext/harvest/harvesters/ckanharvester.py +++ b/ckanext/harvest/harvesters/ckanharvester.py @@ -308,23 +308,24 @@ class CKANHarvester(HarvesterBase): validated_org = None remote_org = package_dict['owner_org'] context = {'model': model, 'session': Session, 'user': 'harvest'} - - try: - data_dict = {'id': remote_org} - org = get_action('organization_show')(context, data_dict) - validated_org = org['id'] - except NotFound, e: - log.info('Organization %s is not available' % remote_org) - if remote_orgs == 'create': - try: - org = self._get_group(harvest_object.source.url, remote_org) - for key in ['packages', 'created', 'users', 'groups', 'tags', 'extras', 'display_name', 'type']: - org.pop(key, None) - get_action('organization_create')(context, org) - log.info('Organization %s has been newly created' % remote_org) - validated_org = org['id'] - except: - log.error('Could not get remote org %s' % remote_org) + + if remote_org: + try: + data_dict = {'id': remote_org} + org = get_action('organization_show')(context, data_dict) + validated_org = org['id'] + except NotFound, e: + log.info('Organization %s is not available' % remote_org) + if remote_orgs == 'create': + try: + org = self._get_group(harvest_object.source.url, remote_org) + for key in ['packages', 'created', 'users', 'groups', 'tags', 'extras', 'display_name', 'type']: + org.pop(key, None) + get_action('organization_create')(context, org) + log.info('Organization %s has been newly created' % remote_org) + validated_org = org['id'] + except: + log.error('Could not get remote org %s' % remote_org) package_dict['owner_org'] = validated_org