[Kimchi-devel] [PATCH] kimchi.control.utils: fix request parsing in generate_action_handler()

Sheldon shaohef at linux.vnet.ibm.com
Mon Mar 3 08:00:50 UTC 2014


Reviewed-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

On 03/01/2014 10:12 PM, zhshzhou at linux.vnet.ibm.com wrote:
> From: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
>
> generate_action_handler() parses the request and collects the action
> arguments. The problem is it calls parse_request() in a generation
> expression. This implies parse_request() is called for each action
> argument. However parse_request() should be called only once, because it
> reads over the request body and turns it to a dict. When it is called a
> second time, the request body is already over, so parse_request() fails.
>
> This patch stores the result from parse_request() in a variable, and
> uses the variable in the generation expression.
>
> Signed-off-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
> ---
>   src/kimchi/control/base.py | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
> index 61b4341..48f1949 100644
> --- a/src/kimchi/control/base.py
> +++ b/src/kimchi/control/base.py
> @@ -65,8 +65,8 @@ class Resource(object):
>               try:
>                   model_args = list(self.model_args)
>                   if action_args is not None:
> -                    model_args.extend(parse_request()[key]
> -                                      for key in action_args)
> +                    request = parse_request()
> +                    model_args.extend(request[key] for key in action_args)
>                   fn = getattr(self.model, model_fn(self, action_name))
>                   ident = fn(*model_args)
>                   self._redirect(ident)


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list