Revert "Fix how Mistral prepares data for evaluating a YAQL expression"
This reverts commit a39db2d3dc
.
Change-Id: Ib45ad50cd1523e079b780e953091ddedbd49a54a
Related-bug: #1816026
This commit is contained in:
parent
a39db2d3dc
commit
1d16d2ffba
|
@ -13,7 +13,6 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
import six
|
|
||||||
|
|
||||||
from mistral.db.v2 import api as db_api
|
from mistral.db.v2 import api as db_api
|
||||||
from mistral.services import workflows as wf_service
|
from mistral.services import workflows as wf_service
|
||||||
|
@ -432,42 +431,3 @@ class YAQLFunctionsEngineTest(engine_test_base.EngineTestCase):
|
||||||
self.assertIsNotNone(json_str)
|
self.assertIsNotNone(json_str)
|
||||||
self.assertIn('"key1": "foo"', json_str)
|
self.assertIn('"key1": "foo"', json_str)
|
||||||
self.assertIn('"key2": "bar"', json_str)
|
self.assertIn('"key2": "bar"', json_str)
|
||||||
|
|
||||||
def test_built_in_str_function(self):
|
|
||||||
wf_text = """---
|
|
||||||
version: '2.0'
|
|
||||||
|
|
||||||
wf:
|
|
||||||
input:
|
|
||||||
- my_list
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
task1:
|
|
||||||
publish:
|
|
||||||
val: <% str($.my_list) %>
|
|
||||||
"""
|
|
||||||
|
|
||||||
wf_service.create_workflows(wf_text)
|
|
||||||
|
|
||||||
wf_ex = self.engine.start_workflow(
|
|
||||||
'wf',
|
|
||||||
wf_input={
|
|
||||||
'my_list': [
|
|
||||||
{
|
|
||||||
'k1': 'v1',
|
|
||||||
'k2': 'v2'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
self.await_workflow_success(wf_ex.id)
|
|
||||||
|
|
||||||
with db_api.transaction(read_only=True):
|
|
||||||
wf_ex = db_api.get_workflow_execution(wf_ex.id)
|
|
||||||
|
|
||||||
val = wf_ex.task_executions[0].published['val']
|
|
||||||
|
|
||||||
self.assertIsInstance(val, six.string_types)
|
|
||||||
self.assertIn('[', val)
|
|
||||||
self.assertIn(']', val)
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import six
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
@ -40,27 +39,6 @@ LOG = logging.getLogger(__name__)
|
||||||
ROOT_YAQL_CONTEXT = None
|
ROOT_YAQL_CONTEXT = None
|
||||||
|
|
||||||
|
|
||||||
def _convert_yaql_input_data(obj, rec=None):
|
|
||||||
# NOTE(rakhmerov): We have to define our own wrapper function
|
|
||||||
# around the function 'convert_input_data' from 'yaql_utils'
|
|
||||||
# because the latter always converts all sequences (except strings)
|
|
||||||
# into tuples, and it in turn breaks a number of things. For example,
|
|
||||||
# if we use the built-in 'str' YAQL function with an argument of the
|
|
||||||
# type 'list' then the result will be '(item1, item2 ..., itemN,)'
|
|
||||||
# instead of '[item1, item2 ..., itemN]'.
|
|
||||||
# So we override this behavior for sequences that are not strings and
|
|
||||||
# tuples.
|
|
||||||
if rec is None:
|
|
||||||
rec = _convert_yaql_input_data
|
|
||||||
|
|
||||||
if (isinstance(obj, yaql_utils.SequenceType) and
|
|
||||||
not isinstance(obj, six.string_types) and
|
|
||||||
not isinstance(obj, tuple)):
|
|
||||||
return list(rec(t, rec) for t in obj)
|
|
||||||
else:
|
|
||||||
return yaql_utils.convert_input_data(obj, rec)
|
|
||||||
|
|
||||||
|
|
||||||
def get_yaql_context(data_context):
|
def get_yaql_context(data_context):
|
||||||
global ROOT_YAQL_CONTEXT
|
global ROOT_YAQL_CONTEXT
|
||||||
|
|
||||||
|
@ -70,7 +48,7 @@ def get_yaql_context(data_context):
|
||||||
_register_yaql_functions(ROOT_YAQL_CONTEXT)
|
_register_yaql_functions(ROOT_YAQL_CONTEXT)
|
||||||
|
|
||||||
new_ctx = ROOT_YAQL_CONTEXT.create_child_context()
|
new_ctx = ROOT_YAQL_CONTEXT.create_child_context()
|
||||||
new_ctx['$'] = _convert_yaql_input_data(data_context)
|
new_ctx['$'] = yaql_utils.convert_input_data(data_context)
|
||||||
|
|
||||||
if isinstance(data_context, dict):
|
if isinstance(data_context, dict):
|
||||||
new_ctx['__env'] = data_context.get('__env')
|
new_ctx['__env'] = data_context.get('__env')
|
||||||
|
|
Loading…
Reference in New Issue