Closed roll closed 5 years ago
@amercader Please review and test.
It works for me (still testing ckan source because my harvester doesn't want to finish reharvesting).
Upd. For ckan it doesn't work on harvesting because the ckan harvester doesn't update not changed datasets. But it works if we change some topic (via jobs)
@amercader Could you please re-take a look?
I tested on manually created dataset because still having this harvesting problem.
@roll there were some hardcore low-level CKAN things that prevented the harvesting from working. The patch below fixed the errors for me:
data[('groups', )] = [{'name': 'census'}, {'name': 'food'}]
but this:
data[('groups', 0, 'name')] = 'census'
data[('groups', 1, 'name')] = 'food'
diff --git a/ckanext/lacounts/validators.py b/ckanext/lacounts/validators.py
index 0734688..16b7cea 100644
--- a/ckanext/lacounts/validators.py
+++ b/ckanext/lacounts/validators.py
@@ -70,10 +70,14 @@ def convert_groups_override(key, data, errors, context):
package = None
group_ids = set()
group_override_ids = set(value if isinstance(value, list) else value.strip('{}').split(','))
- if data.get(('id',)):
+ if data.get(('id',)) and data[('id', )] is not toolkit.missing:
+
context = {'model': model}
- package = toolkit.get_action('package_show')(context, {'id': data[('id',)]})
- group_ids = set(map(lambda group: group['id'], package['groups']))
+ try:
+ package = toolkit.get_action('package_show')(context, {'id': data[('id',)]})
+ group_ids = set(map(lambda group: group['id'], package['groups']))
+ except toolkit.ObjectNotFound:
+ pass
# Form groups_override value
groups_add = group_override_ids.difference(group_ids)
@@ -95,4 +99,5 @@ def convert_groups_override(key, data, errors, context):
# Save groups_override/groups
data[('groups_override',)] = json.dumps(groups_override)
- data[('groups',)] = groups
+ for index, group in enumerate(groups):
+ data[('groups', index, 'id')] = group['id']
Functionality works fine, nice work