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
This commit is contained in:

committed by
Gerrit Code Review

parent
95b0fa9660
commit
c61cf7670e
@@ -28,14 +28,17 @@ class ExecutionManager(base.ResourceManager):
|
|||||||
resource_class = Execution
|
resource_class = Execution
|
||||||
|
|
||||||
def _get_context_as_str(self, context):
|
def _get_context_as_str(self, context):
|
||||||
msg = 'Context must be a dictionary or json compatible string.'
|
msg = 'Context must be a dictionary or json compatible string:'
|
||||||
context_as_str = str(context)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
json.loads(context_as_str)
|
if isinstance(context, dict):
|
||||||
|
context = json.dumps(context)
|
||||||
|
else:
|
||||||
|
json.loads(context)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ex.IllegalArgumentException(msg + e)
|
raise ex.IllegalArgumentException(' '.join((msg, str(e))))
|
||||||
return context_as_str
|
|
||||||
|
return context
|
||||||
|
|
||||||
def create(self, workbook_name, task, context=None):
|
def create(self, workbook_name, task, context=None):
|
||||||
self._ensure_not_empty(workbook_name=workbook_name, task=task)
|
self._ensure_not_empty(workbook_name=workbook_name, task=task)
|
||||||
@@ -45,7 +48,7 @@ class ExecutionManager(base.ResourceManager):
|
|||||||
'task': task
|
'task': task
|
||||||
}
|
}
|
||||||
|
|
||||||
if context is not None:
|
if context:
|
||||||
data['context'] = self._get_context_as_str(context)
|
data['context'] = self._get_context_as_str(context)
|
||||||
|
|
||||||
return self._create('/workbooks/%s/executions' % workbook_name, data)
|
return self._create('/workbooks/%s/executions' % workbook_name, data)
|
||||||
|
Reference in New Issue
Block a user