From c61cf7670e8dcfe6c2c03a53e62f484dc73863ea Mon Sep 17 00:00:00 2001 From: Kirill Izotov Date: Mon, 10 Mar 2014 12:51:59 +0700 Subject: [PATCH] Fix context serialization in Execution.create Proper serialization for context passed as dict. Also: * fix type casting in Exception message Change-Id: I3ad26ebba52ae9ed55c8f56b774f5017dcbd83ff Closes-Bug: #1290214 --- mistralclient/api/executions.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mistralclient/api/executions.py b/mistralclient/api/executions.py index abd4ab23..81634d35 100644 --- a/mistralclient/api/executions.py +++ b/mistralclient/api/executions.py @@ -28,14 +28,17 @@ class ExecutionManager(base.ResourceManager): resource_class = Execution def _get_context_as_str(self, context): - msg = 'Context must be a dictionary or json compatible string.' - context_as_str = str(context) + msg = 'Context must be a dictionary or json compatible string:' try: - json.loads(context_as_str) + if isinstance(context, dict): + context = json.dumps(context) + else: + json.loads(context) except Exception as e: - raise ex.IllegalArgumentException(msg + e) - return context_as_str + raise ex.IllegalArgumentException(' '.join((msg, str(e)))) + + return context def create(self, workbook_name, task, context=None): self._ensure_not_empty(workbook_name=workbook_name, task=task) @@ -45,7 +48,7 @@ class ExecutionManager(base.ResourceManager): 'task': task } - if context is not None: + if context: data['context'] = self._get_context_as_str(context) return self._create('/workbooks/%s/executions' % workbook_name, data)