[ckan-dev] TypeError with get_action('group_show') in harvester, CKAN v2.2.1

Rachel Knowler rachel.knowler at liip.ch
Wed Sep 24 08:39:13 UTC 2014


Hi dev list,

I'm writing a harvester extension for a v2.2.1 CKAN instance, which 
needs to check if a group exists, and if not, create it. It does this 
using get_action('group_show')(context, data_dict).

When I run the harvester, though, I get this error: TypeError: No object 
(name: request) has been registered for this thread

It seems that the package_search action checks all the extensions for 
before_search methods 
(https://github.com/ckan/ckan/blob/release-v2.2.1/ckan/logic/action/get.py#L1445). 
The multilingual core extension has such a method, which includes this 
line 
(https://github.com/ckan/ckan/blob/release-v2.0.4/ckanext/multilingual/plugin.py#L153):

current_lang = pylons.request.environ['CKAN_LANG']

I guess that since I'm calling this function in a command-line context, 
not via the website, there is no Pylons request and I get the error shown.

The weird thing is that none of this code seems to have changed since 
v2.0.4, and other harvesters with this code run just fine on my v2.0.4 
instances! As a temporary workaround, I've just removed all the 
multilingual extensions from my development.ini, and the harvester 
works. This isn't a good long-term solution, though. Does anyone have 
any insight on what I could do better, or if this is a bug in v2.2.1? 
Code snippet and stack trace are pasted below.

Thanks,
Rachel


Method in my harvester:

     def _find_or_create_groups(self, groups, context):
         log.debug('Group names: %s' % groups)
         group_ids = []
         for group_name in groups:
             data_dict = {
                 'id': group_name,
                 'name': munge_title_to_name(group_name),
                 'title': group_name
             }
             try:
                 group = get_action('group_show')(context, data_dict)
                 log.info('found the group ' + group['id'])
             except:
                 group = get_action('group_create')(context, data_dict)
                 log.info('created the group ' + group['id'])
             group_ids.append(group['id'])

         log.debug('Group ids: %s' % group_ids)
         return group_ids


Stack trace:

2014-09-24 08:16:04,530 DEBUG [ckanext.salsah.harvester] In 
SalsahHarvester import_stage
2014-09-24 08:16:04,702 ERROR [ckanext.salsah.harvester] No object 
(name: request) has been registered for this thread
Traceback (most recent call last):
   File "/vagrant/ckanext-salsah/ckanext/salsah/harvester.py", line 247, 
in import_stage
     data_dict)
   File "/home/vagrant/pyenv/src/ckan/ckan/logic/__init__.py", line 425, 
in wrapped
     result = _action(context, data_dict, **kw)
   File "/home/vagrant/pyenv/src/ckan/ckan/logic/action/create.py", line 
723, in organization_create
     return _group_or_org_create(context, data_dict, is_org=True)
   File "/home/vagrant/pyenv/src/ckan/ckan/logic/action/create.py", line 
602, in _group_or_org_create
     return model_dictize.group_dictize(group, context)
   File 
"/home/vagrant/pyenv/src/ckan/ckan/lib/dictization/model_dictize.py", 
line 380, in group_dictize
     search_results = logic.get_action('package_search')(context_, q)
   File "/home/vagrant/pyenv/src/ckan/ckan/logic/__init__.py", line 425, 
in wrapped
     result = _action(context, data_dict, **kw)
   File "/home/vagrant/pyenv/src/ckan/ckan/logic/action/get.py", line 
1447, in package_search
     data_dict = item.before_search(data_dict)
   File 
"/home/vagrant/pyenv/local/lib/python2.7/site-packages/ckanext/multilingual/plugin.py", 
line 153, in before_search
     current_lang = pylons.request.environ['CKAN_LANG']
   File 
"/home/vagrant/pyenv/local/lib/python2.7/site-packages/paste/registry.py", 
line 137, in __getattr__
     return getattr(self._current_obj(), attr)
   File 
"/home/vagrant/pyenv/local/lib/python2.7/site-packages/paste/registry.py", 
line 197, in _current_obj
     'thread' % self.____name__)
TypeError: No object (name: request) has been registered for this thread
Traceback (most recent call last):
   File "/home/vagrant/pyenv/bin/paster", line 9, in <module>
     load_entry_point('PasteScript==1.7.5', 'console_scripts', 'paster')()
   File 
"/home/vagrant/pyenv/local/lib/python2.7/site-packages/paste/script/command.py", 
line 104, in run
     invoke(command, command_name, options, args[1:])
   File 
"/home/vagrant/pyenv/local/lib/python2.7/site-packages/paste/script/command.py", 
line 143, in invoke
     exit_code = runner.run(args)
   File 
"/home/vagrant/pyenv/local/lib/python2.7/site-packages/paste/script/command.py", 
line 238, in run
     result = self.command()
   File 
"/vagrant/ckanext-harvest/ckanext/harvest/commands/harvester.py", line 
136, in command
     fetch_callback(consumer, method, header, body)
   File "/vagrant/ckanext-harvest/ckanext/harvest/queue.py", line 294, 
in fetch_callback
     fetch_and_import_stages(harvester, obj)
   File "/vagrant/ckanext-harvest/ckanext/harvest/queue.py", line 311, 
in fetch_and_import_stages
     success_import = harvester.import_stage(obj)
   File "/vagrant/ckanext-salsah/ckanext/salsah/harvester.py", line 247, 
in import_stage
     data_dict)
   File "/home/vagrant/pyenv/src/ckan/ckan/logic/__init__.py", line 425, 
in wrapped
     result = _action(context, data_dict, **kw)
   File "/home/vagrant/pyenv/src/ckan/ckan/logic/action/create.py", line 
723, in organization_create
     return _group_or_org_create(context, data_dict, is_org=True)
   File "/home/vagrant/pyenv/src/ckan/ckan/logic/action/create.py", line 
602, in _group_or_org_create
     return model_dictize.group_dictize(group, context)
   File 
"/home/vagrant/pyenv/src/ckan/ckan/lib/dictization/model_dictize.py", 
line 380, in group_dictize
     search_results = logic.get_action('package_search')(context_, q)
   File "/home/vagrant/pyenv/src/ckan/ckan/logic/__init__.py", line 425, 
in wrapped
     result = _action(context, data_dict, **kw)
   File "/home/vagrant/pyenv/src/ckan/ckan/logic/action/get.py", line 
1447, in package_search
     data_dict = item.before_search(data_dict)
   File 
"/home/vagrant/pyenv/local/lib/python2.7/site-packages/ckanext/multilingual/plugin.py", 
line 153, in before_search
     current_lang = pylons.request.environ['CKAN_LANG']
   File 
"/home/vagrant/pyenv/local/lib/python2.7/site-packages/paste/registry.py", 
line 137, in __getattr__
     return getattr(self._current_obj(), attr)
   File 
"/home/vagrant/pyenv/local/lib/python2.7/site-packages/paste/registry.py", 
line 197, in _current_obj
     'thread' % self.____name__)
TypeError: No object (name: request) has been registered for this thread



-- 
Liip AG // Limmatstrasse 183 // CH-8005 Zürich
Tel +41 43 500 39 80 // Mob +41 78 658 26 12 // www.liip.ch




More information about the ckan-dev mailing list