[ckan-dev] ckan 2.2 issue (seems like)

Foobar foo.bar.0000 at gmail.com
Mon May 12 11:20:31 UTC 2014


Hi,

  Sorry for posting this into question, but this is basically same question.

  How do you call original function inside function you just override? 
So basically how do you call it directly? Example if I just want to add 
one line before or after user_login login action now I need to copy 
whole user_login functionality to my code and add extra functionality 
there. Then if we update CKAN to next version I need to check all the 
functions to see what are changed and change my code. Not so maintanable 
in long run.

  I made a workaround for this, but I would like to know if there is 
better way than what I used below?

def get_original_method(module_name, method_name):
     """ Example get_original_method('ckan.logic.action.create', 
'user_create') """
     __import__(module_name)
     imported_module = sys.modules[module_name]
     reimport_module = imp.load_compiled('%s.reimport' % module_name, 
imported_module.__file__)

     return getattr(reimport_module, method_name)

Best regards



On 08/05/14 21:17, Vitor Baptista wrote:
> Hi Pabitra,
>
> You shouldn't be calling the action functions directly, because 
> another plugin might modify them. Try getting them through 
> get_action() and see if it solves your problem.
>
> Cheers,
>
>
> 2014-05-08 13:19 GMT-03:00 Pabitra Dash <pkdash_reena at hotmail.com 
> <mailto:pkdash_reena at hotmail.com>>:
>
>     Hi Everyone,
>
>     It seems now there is no way to call an action function directly
>     in ckan 2.2. One has to use get_action() method. That is perhaps
>     causing the infinite loop issue for me where I am overriding a
>     ckan action function. I see the following new piece of code in
>     logic __inti__.py which forces to use get_action() method to use a
>     action function.
>
>      def replaced_action(action_name):
>                 def warn(context, data_dict):
>     log.critical('Action `%s` is being called directly '
>     'all action calls should be accessed via '
>     'logic.get_action' % action_name)
>     *return get_action(action_name)(context, data_dict)*
>                 return warn
>
>     If I can't resolve this issue I have to roll back to ckan 2.1.
>
>     Would very much appreciate some help on this.
>
>     Thanks,
>     Pabitra
>
>
>
>
>
>     ------------------------------------------------------------------------
>     From: pkdash_reena at hotmail.com <mailto:pkdash_reena at hotmail.com>
>     To: ckan-dev at lists.okfn.org <mailto:ckan-dev at lists.okfn.org>
>     Date: Wed, 7 May 2014 23:15:45 -0500
>
>     Subject: Re: [ckan-dev] ckan 2.2 issue (seems like)
>
>     Ian,
>
>     I am not sure If I fully understand your question. However, I will
>     try to show the code structure here:
>
>     skeleton code in plugin.py file:
>
>     from ckan.logic.action.get import *user_show*
>     import ckan.plugin as p
>
>     def show_user(context, data_dict):
>         # code to manipulating the data_dict here
>         return *user_show*(context, data_dict)   #*this where the
>     infinite loop happens*
>
>     class MyPlugin(p.SingletonPlugin):
>         p.implements(p.IActions)
>
>       # other code stuff here
>
>
>        def get_actions(self):
>            return {'*user_show*': 'show_user}
>
>
>     Thanks,
>     Pabitra
>
>
>
>     ------------------------------------------------------------------------
>     Date: Wed, 7 May 2014 19:58:02 -0400
>     From: ian at excess.org <mailto:ian at excess.org>
>     To: ckan-dev at lists.okfn.org <mailto:ckan-dev at lists.okfn.org>
>     Subject: Re: [ckan-dev] ckan 2.2 issue (seems like)
>
>
>     On 7 May 2014 19:54, "Pabitra Dash" <pkdash_reena at hotmail.com
>     <mailto:pkdash_reena at hotmail.com>> wrote:
>     >
>     > Hi All,
>     >
>     > The code that I have in my plugin and that used to work in ckan
>     2.1  is no more working in ckan 2.2. I am getting an infinite loop
>     in part of the code where I am overriding a logic action function
>     ('user_show') using the IActions interface get_actions(). Within
>     my custom function show_user() I am calling the
>     ckan.logic.action.get.user_show(). It used to work in ckan 2.1 but
>     after upgrading to ckan 2.2 I am getting an infinite loop inside
>     my show_user() function.
>
>     How are you calling the original? Are you importing the action at
>     the module level?
>
>
>     _______________________________________________ ckan-dev mailing
>     list ckan-dev at lists.okfn.org <mailto:ckan-dev at lists.okfn.org>
>     https://lists.okfn.org/mailman/listinfo/ckan-dev Unsubscribe:
>     https://lists.okfn.org/mailman/options/ckan-dev
>
>     _______________________________________________ ckan-dev mailing
>     list ckan-dev at lists.okfn.org <mailto:ckan-dev at lists.okfn.org>
>     https://lists.okfn.org/mailman/listinfo/ckan-dev Unsubscribe:
>     https://lists.okfn.org/mailman/options/ckan-dev
>
>     _______________________________________________
>     ckan-dev mailing list
>     ckan-dev at lists.okfn.org <mailto:ckan-dev at lists.okfn.org>
>     https://lists.okfn.org/mailman/listinfo/ckan-dev
>     Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>
>
>
>
> -- 
>
> Vítor Baptista
>
> Developer  |http://vitorbaptista.com | LinkedIn 
> <http://www.linkedin.com/in/vitorbaptista> | @vitorbaptista 
> <http://twitter.com/vitorbaptista>
>
> The Open Knowledge Foundation <http://okfn.org>
>
> /Empowering through Open Knowledge/
>
> http://okfn.org/  | @okfn <http://twitter.com/okfn>  | OKF on Facebook 
> <https://www.facebook.com/OKFNetwork>  | Blog <http://blog.okfn.org/> 
>  | Newsletter <http://okfn.org/about/newsletter/>
>
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140512/ff29067d/attachment-0003.html>


More information about the ckan-dev mailing list