diff --git a/ckan/lib/dictization/model_dictize.py b/ckan/lib/dictization/model_dictize.py index 80c43a4aadd..fd043e9e2d3 100644 --- a/ckan/lib/dictization/model_dictize.py +++ b/ckan/lib/dictization/model_dictize.py @@ -142,8 +142,6 @@ def resource_dictize(res, context): model = context['model'] resource = d.table_dictize(res, context) resource_group_id = resource['resource_group_id'] - resource_group = model.Session.query( - model.ResourceGroup).get(resource_group_id) extras = resource.pop("extras", None) if extras: resource.update(extras) @@ -151,6 +149,8 @@ def resource_dictize(res, context): # some urls do not have the protocol this adds http:// to these url = resource['url'] if resource.get('url_type') == 'upload' and not context.get('for_edit'): + resource_group = model.Session.query( + model.ResourceGroup).get(resource_group_id) last_part = url.split('/')[-1] cleaned_name = munge.munge_filename(last_part) resource['url'] = h.url_for(controller='package', diff --git a/ckan/lib/uploader.py b/ckan/lib/uploader.py index 27c998dc24c..b46f186ccb9 100644 --- a/ckan/lib/uploader.py +++ b/ckan/lib/uploader.py @@ -151,6 +151,7 @@ class ResourceUpload(object): def __init__(self, resource): path = get_storage_path() if not path: + self.storage_path = None return self.storage_path = os.path.join(path, 'resources') try: @@ -187,6 +188,8 @@ def get_path(self, id): def upload(self, id, max_size=10): + if not self.storage_path: + return directory = self.get_directory(id) filepath = self.get_path(id) if self.filename: diff --git a/ckan/logic/action/update.py b/ckan/logic/action/update.py index e1b59b5b072..1d4dfb30efc 100644 --- a/ckan/logic/action/update.py +++ b/ckan/logic/action/update.py @@ -235,7 +235,7 @@ def resource_update(context, data_dict): resource = pkg_dict['resources'][n] upload.upload(resource['id'], uploader.get_max_resource_size()) model.repo.commit() - return resource + return _get_action('resource_show')(context, {'id': id}) def package_update(context, data_dict): diff --git a/ckan/tests/logic/test_action.py b/ckan/tests/logic/test_action.py index 70857c5eda2..316d6533a5e 100644 --- a/ckan/tests/logic/test_action.py +++ b/ckan/tests/logic/test_action.py @@ -832,10 +832,10 @@ def test_19_update_resource(self): resource_updated.pop('url') resource_updated.pop('revision_id') - resource_updated.pop('revision_timestamp') + resource_updated.pop('revision_timestamp', None) resource_created.pop('url') resource_created.pop('revision_id') - resource_created.pop('revision_timestamp') + resource_created.pop('revision_timestamp', None) assert_equal(resource_updated, resource_created) def test_20_task_status_update(self):