Skip to content

Conversation

fanjinfei
Copy link
Contributor

@fanjinfei fanjinfei commented Mar 20, 2017

Fixes #
Add chained_action support so that user can modify previously defined actions.

Proposed fixes:

Use chained_action decorator.

Features:

  • includes tests covering changes
  • includes updated documentation
  • includes user-visible changes
  • includes API changes
  • includes bugfix for possible backport

Please [X] all the boxes above that apply

@fanjinfei fanjinfei force-pushed the ckanmaster branch 2 times, most recently from f190e8f to abac05d Compare March 20, 2017 19:24
@@ -312,6 +313,15 @@ def clear_actions_cache():
_actions.clear()


def chained_action(func):
func.__is_chained_action__ = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__double_underscore__ should be reserved for attributes that have a special meaning to the python interpreter. You can use func.chained_action = True here instead.

if name not in fetched_actions:
raise NotFound('The action %r is not found for chained action' % (
name))
for func in func_list:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be for func in reversed(func_list)

For all other interfaces we have a "first plugin wins" pattern, so the first plugin declaring a chained action in the plugin list should be the first called for that action.

@wardi
Copy link
Contributor

wardi commented Mar 21, 2017

This also needs a mention in docs next to where IActions is described

@fanjinfei fanjinfei force-pushed the ckanmaster branch 3 times, most recently from 3ce9e02 to bf0f683 Compare March 21, 2017 16:36
By decrorating a function with the 'ckan.plugins.toolkit.chained_action,
the action will be chained to another function defined in plugins with a
"first plugin wins" pattern, which means the first plugin declaring a
chained action should be called first.
Copy link
Contributor

@wardi wardi Mar 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chained actions must be defined as action_function(original_action, context, data_dict) where the first parameter will be set to the action function in the next plugin or in core ckan. The chained action may call the original_action function, optionally passing different values, handling exceptions, returning different values and/or raising different exceptions to the caller.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ I meant to say I would add something like this paragraph to the one you've written.

filters=data_dict[u'filters'],
limit=10,)
result = up_func(context, data_dict)
deleted_count = res.get(u'total', 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of modifying a global why not return this as part of the response to demonstrate that this is possible?

return result


class ChainedDataStorePlugin(p.SingletonPlugin):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about ExampleDatastoreDeleteWithCountPlugin

ChainedDatastorePlugin sounds like something a user might want to use..

@wardi
Copy link
Contributor

wardi commented Mar 28, 2017

@fanjinfei please update the name to fix the test and I'll merge

@fanjinfei
Copy link
Contributor Author

@wardi test case fixed

@wardi wardi merged commit f9f7017 into ckan:master Mar 28, 2017
@wardi
Copy link
Contributor

wardi commented Mar 28, 2017

@fanjinfei great work!

jrdh added a commit to jrdh/ckan that referenced this pull request Jan 23, 2018
In a prior peace of work the ability to chain action functions was
added, this commit extends that concept to authentication functions
and adds tests for it.

Action chaining work: ckan#3494
@wardi wardi mentioned this pull request Oct 31, 2023
5 tasks
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

Successfully merging this pull request may close these issues.

2 participants