From 4734909912363b6814f724d070653d098dac504f Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 24 Apr 2024 00:18:30 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20The=20`EventMatchResult`=20objec?= =?UTF-8?q?t=20shouldn't=20be=20initialized=20with=20`args`=20from=20the?= =?UTF-8?q?=20event.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If there's a good use-case for overriding `Event._matches_condition` with a logic that also parses the event arguments, then those arguments should be accessed directly from the event object, not from the match result. Initializing `EventMatchResult` with the arguments from the event means that, if `EventMatchResult.parsed_args` are populated with custom extracted arguments, then the upstream event arguments will also be modified. If the event is matched against multiple conditions, this will result in the extracted tokens getting modified by each `matches_condition` iteration. --- platypush/message/event/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platypush/message/event/__init__.py b/platypush/message/event/__init__.py index 465b981add..ff4c769042 100644 --- a/platypush/message/event/__init__.py +++ b/platypush/message/event/__init__.py @@ -220,7 +220,7 @@ class Event(Message): :param condition: The platypush.event.hook.EventCondition object """ - result = EventMatchResult(is_match=False, parsed_args=self.args) + result = EventMatchResult(is_match=False) match_scores = [] if not isinstance(self, condition.type):