Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash using IPackageController extension after_update to make dataset private in CKAN 2.2.2 #2408

Closed
glagnar opened this issue Apr 28, 2015 · 3 comments
Assignees

Comments

@glagnar
Copy link

glagnar commented Apr 28, 2015

I have created this extension, to override the 'private' property of datasets. It must always be private for new datasets.

class SetStateForPendingValidationPlugin(plugins.SingletonPlugin):
   plugins.implements(plugins.IPackageController, inherit=True)

   def after_update(self, context, data_dict):
    if 'state' not in data_dict or ( 'state' in data_dict and data_dict['state'] == 'active'):
        if 'private' not in data_dict or ( 'private' in data_dict and data_dict['private'] == False):
            data_dict['private'] = True
            log.info("CKAN to send %r: ", data_dict)
            toolkit.get_action('package_update')(context, data_dict)

This works fine for links, but not when using the filestore. When using filestore, and an administrator creates a dataset with a file, everything works fine - but when it is an ordinary user the system crashes. It doesn't seem to be the file uploader but rather the page that should display the new dataset after completion.

@wardi
Copy link
Contributor

wardi commented Apr 30, 2015

@glagnar calling package_update from within an after_update method seems like a bad idea. I'm reasonably sure the package_update code wasn't designed to be re-entrant.

Could you try just modifying the data_dict from a before_update method? Or use the approach I'm more familiar with: implement it with validators in an IDatasetForm plugin. I know that would work.

@glagnar
Copy link
Author

glagnar commented May 1, 2015

@wardi Thanks for the suggestions. Unfortunately the IPackageController does not have a before_update. The code I have submitted seems to work fine - unless the user is not administrator. I suspect a bug in CKAN 2.2.2. I have just now installed my plugin in CKAN 2.3 and everything seems to work perfectly.

@glagnar glagnar changed the title Crash using IPackageController extension after_update to make dataset private Crash using IPackageController extension after_update to make dataset private in CKAN 2.2.2 May 1, 2015
@wardi
Copy link
Contributor

wardi commented May 1, 2015

Confirming how little I know about IPackageController :-)

Calling package_update from within a function that is called by package_update is still a really bad idea, and recommend you use an IDatasetForm validator instead.

@wardi wardi closed this as completed May 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants