From 5461bf532c8e42536343bddf5f735eaf268f1488 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 4 Jan 2018 23:10:53 +0100 Subject: [PATCH] Copy the arguments before creating the action and re-create the action every time to make sure that the context is not polluted by previous executions --- platypush/event/hook.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/platypush/event/hook.py b/platypush/event/hook.py index 788acf61..2886041e 100644 --- a/platypush/event/hook.py +++ b/platypush/event/hook.py @@ -1,3 +1,4 @@ +import copy import json import logging import re @@ -71,7 +72,8 @@ class EventAction(Request): def __init__(self, target=None, action=None, **args): if target is None: target=Config.get('device_id') - super().__init__(target=target, action=action, **args) + args_copy = copy.deepcopy(args) + super().__init__(target=target, action=action, **args_copy) def execute(self, **context): @@ -142,9 +144,9 @@ class EventHook(object): if 'then' in hook: if isinstance(hook['then'], list): - actions = [EventAction.build(action) for action in hook['then']] + actions = hook['then'] else: - actions = [EventAction.build(hook['then'])] + actions = [hook['then']] return cls(name=name, condition=condition, actions=actions, priority=priority) @@ -166,7 +168,8 @@ class EventHook(object): logging.info('Running hook {} triggered by an event'.format(self.name)) for action in self.actions: - action.execute(event=event, **result.parsed_args) + a = EventAction.build(action) + a.execute(event=event, **result.parsed_args) # vim:sw=4:ts=4:et: