-
Notifications
You must be signed in to change notification settings - Fork 2.1k
support chained action in plugins #3494
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
Conversation
f190e8f
to
abac05d
Compare
ckan/logic/__init__.py
Outdated
@@ -312,6 +313,15 @@ def clear_actions_cache(): | |||
_actions.clear() | |||
|
|||
|
|||
def chained_action(func): | |||
func.__is_chained_action__ = True |
There was a problem hiding this comment.
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.
ckan/logic/__init__.py
Outdated
if name not in fetched_actions: | ||
raise NotFound('The action %r is not found for chained action' % ( | ||
name)) | ||
for func in func_list: |
There was a problem hiding this comment.
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.
This also needs a mention in docs next to where IActions is described |
3ce9e02
to
bf0f683
Compare
ckan/plugins/interfaces.py
Outdated
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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..
@fanjinfei please update the name to fix the test and I'll merge |
@wardi test case fixed |
@fanjinfei great work! |
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
Fixes #
Add chained_action support so that user can modify previously defined actions.
Proposed fixes:
Use chained_action decorator.
Features:
Please [X] all the boxes above that apply