diff --git a/mistral/config.py b/mistral/config.py index 76a1b56ea..241f73a3c 100644 --- a/mistral/config.py +++ b/mistral/config.py @@ -560,6 +560,23 @@ yaql_opts = [ help=_('The memory usage quota (in bytes) for all data produced by ' 'the expression (or any part of it). -1 means no limitation.') ), + cfg.BoolOpt( + 'convert_input_data', + default=True, + help=_('Enables input data conversion for YAQL expressions. If set ' + 'to True then YAQL will convert mutable data structures ' + '(lists, dicts, sets) into their immutable versions. That ' + 'will allow them to work with some constructs that require ' + 'hashable types even if elements are not hashable. For ' + 'example, it will be possible to put dicts into a set. ' + 'Although it conflicts with the base principles of such ' + 'collections (e.g. we cannot put a non-hashable type into ' + 'a set just because otherwise it will not work correctly) the ' + 'YAQL library itself allows this. ' + 'Disabling input data conversion may give significant ' + 'performance boost if the input data for an expression is ' + 'large.') + ), cfg.BoolOpt( 'convert_tuples_to_lists', default=True, diff --git a/mistral/utils/expression_utils.py b/mistral/utils/expression_utils.py index 1155b10f0..024f34c6b 100644 --- a/mistral/utils/expression_utils.py +++ b/mistral/utils/expression_utils.py @@ -25,6 +25,7 @@ import yaql from yaql.language import utils as yaql_utils +from mistral.config import cfg from mistral.db.v2 import api as db_api from mistral import utils @@ -48,7 +49,11 @@ def get_yaql_context(data_context): _register_yaql_functions(ROOT_YAQL_CONTEXT) new_ctx = ROOT_YAQL_CONTEXT.create_child_context() - new_ctx['$'] = yaql_utils.convert_input_data(data_context) + + new_ctx['$'] = ( + data_context if not cfg.CONF.yaql.convert_input_data + else yaql_utils.convert_input_data(data_context) + ) if isinstance(data_context, dict): new_ctx['__env'] = data_context.get('__env') diff --git a/releasenotes/notes/add_yaql_convert_input_data_config_property-09822dee1f46eb8e.yaml b/releasenotes/notes/add_yaql_convert_input_data_config_property-09822dee1f46eb8e.yaml new file mode 100644 index 000000000..7cb0c0928 --- /dev/null +++ b/releasenotes/notes/add_yaql_convert_input_data_config_property-09822dee1f46eb8e.yaml @@ -0,0 +1,11 @@ +--- +fixes: + - | + Added the "convert_input_data" config property under the "yaql" group. + By default it's set to True which preserves the current behavior so + there's no risk with compatibility. If set to False, it disables the + additional data conversion that was initially added to support some + tricky cases like working with sets of dicts (although dict is not a + hashable type and can't be put into a set). Disabling it give a + significant performance boost in cases when data contexts are very + large.