From 0fd38e0e54a8e0bb84ca5717db89e1587b6a6c79 Mon Sep 17 00:00:00 2001 From: Stefan Oderbolz Date: Wed, 14 Jan 2015 00:10:27 +0100 Subject: [PATCH] Use _get_group as a fallback for remote orgs First try to get a remote org from the remote Action API, if this fails try to use the old rest api call, which works on older CKAN versions. Only if both options fail, its currently not possible to get the remote organization. --- ckanext/harvest/harvesters/ckanharvester.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ckanext/harvest/harvesters/ckanharvester.py b/ckanext/harvest/harvesters/ckanharvester.py index 2c5c4d9..3fb3935 100644 --- a/ckanext/harvest/harvesters/ckanharvester.py +++ b/ckanext/harvest/harvesters/ckanharvester.py @@ -337,7 +337,14 @@ class CKANHarvester(HarvesterBase): log.info('Organization %s is not available' % remote_org) if remote_orgs == 'create': try: - org = self._get_organization(harvest_object.source.url, remote_org) + try: + org = self._get_organization(harvest_object.source.url, remote_org) + except: + # fallback if remote CKAN exposes organizations as groups + # this especially targets older versions of CKAN + log.debug('_get_organization() failed, now trying _get_group()') + 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)