From 5a7068501a63ceb3e89b28b5313fbc55ff5fa9e7 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 10 Sep 2024 19:49:16 +0200 Subject: [PATCH] [request] The action name can be specified either on `action` or `name`. This is for UI compatibility purposes. --- platypush/message/request/__init__.py | 3 ++- platypush/plugins/procedures/__init__.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platypush/message/request/__init__.py b/platypush/message/request/__init__.py index 7a55e65429..8dda18eb7d 100644 --- a/platypush/message/request/__init__.py +++ b/platypush/message/request/__init__.py @@ -64,12 +64,13 @@ class Request(Message): msg = super().parse(msg) args = { 'target': msg.get('target', Config.get('device_id')), - 'action': msg['action'], + 'action': msg.get('action', msg.get('name')), 'args': msg.get('args', {}), 'id': msg['id'] if 'id' in msg else cls._generate_id(), 'timestamp': msg['_timestamp'] if '_timestamp' in msg else time.time(), } + assert args.get('action'), 'No action specified in the request' if 'origin' in msg: args['origin'] = msg['origin'] if 'token' in msg: diff --git a/platypush/plugins/procedures/__init__.py b/platypush/plugins/procedures/__init__.py index 3e66f7631e..cffd2f65f1 100644 --- a/platypush/plugins/procedures/__init__.py +++ b/platypush/plugins/procedures/__init__.py @@ -286,9 +286,10 @@ class ProceduresPlugin(RunnablePlugin, ProcedureEntityManager): @classmethod def _serialize_action(cls, data: Union[Iterable, Dict]) -> Union[Dict, List]: if isinstance(data, dict): - if data.get('action'): + name = data.get('action', data.get('name')) + if name: return { - 'action': data['action'], + 'action': name, **({'args': data['args']} if data.get('args') else {}), }