[ckan-discuss] Difficulty deleting resources

Brian Lee Yung Rowe rowe at muxspace.com
Sat Nov 9 22:51:05 UTC 2013


Hello, 

I am having a trouble deleting resources via the CKAN API. Really what I want to do is update a JSON resource with a newer version of the JSON. I've tried a few different approaches, none of which have succeeded. Any help is greatly appreciated.

Method 1: ckanclient
client = CkanClient('http://odessa.zatonovo.com/api/3', apikey)
client.action('resource_delete', id='cw_articles-2013-11-04.json')

CkanApiNotAuthorizedError                 Traceback (most recent call last)

    538         self.reset()
    539         url = self.get_action_location(action_name)
--> 540         self.open_action_url(url, kwargs)
    541         return self.last_result

Note that the resource_show action works fine:
client.action('resource_show', id='cw_articles-2013-11-04.json')
{u'cache_last_updated': None,
 u'cache_url': None,
 u'created': u'2013-11-06T02:04:22.625862',
 u'description': u'',
 u'format': u'JSON',
 u'hash': u'',
...


Method 2: curl
curl -X POST -d '{ "state":"deleted", "id":"cw_articles-2013-11-04.json"}' -H "Authorization:apikey" "http://odessa.zatonovo.com/api/3/action/resource_delete"

This results in an Internal Server Error, the source of which is a SQL Alchemy assertion error.

[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125] File '/usr/lib/ckan/default/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py', line 475 in execute
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125]   uow
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125] File '/usr/lib/ckan/default/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py', line 45 in save_obj
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125]   uowtransaction)
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125] File '/usr/lib/ckan/default/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py', line 149 in _organize_states_for_save
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125]   mapper.dispatch.before_update(mapper, connection, state)
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125] File '/usr/lib/ckan/default/lib/python2.7/site-packages/sqlalchemy/event.py', line 291 in __call__
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125]   fn(*args, **kw)
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125] File '/usr/lib/ckan/default/lib/python2.7/site-packages/sqlalchemy/orm/events.py', line 363 in wrap
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125]   return wrapped_fn(*arg, **kw)
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125] File '/usr/lib/ckan/default/lib/python2.7/site-packages/vdm/sqlalchemy/base.py', line 606 in before_update
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125]   self.set_revision(instance)
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125] File '/usr/lib/ckan/default/lib/python2.7/site-packages/vdm/sqlalchemy/base.py', line 532 in set_revision
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125]   assert current_rev, 'No revision is currently set for this Session'
[Sat Nov 09 22:06:45 2013] [error] [client 64.131.129.125] AssertionError: No revision is currently set for this Session


Platform info: Ubuntu 12.04.2 LTS

$ apt-cache show python-ckan
Package: python-ckan
Status: install ok installed
Version: 2.0.2-1

Many Thanks,
Brian


More information about the ckan-discuss mailing list