Skip to content

Commit

Permalink
Fixes StackStorm#247 by casting set and dict_key to list type.
Browse files Browse the repository at this point in the history
  • Loading branch information
nzlosh committed Aug 14, 2023
1 parent 4992b11 commit 7a6c643
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.6", "3.8"]
python-version: ["3.6.15", "3.8.17"]
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion orquesta/expressions/functions/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import collections
import collections.abc

from orquesta import constants
from orquesta import exceptions as exc
Expand Down
6 changes: 6 additions & 0 deletions orquesta/expressions/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import collections.abc
import functools
import inspect
import itertools
Expand Down Expand Up @@ -215,6 +216,11 @@ def evaluate(cls, text, data=None):
# Recursively evaluate the expression.
output = cls._evaluate_and_expand(text, data=data)

# Fix #247 by casting dict_keys objects to list. Jinja returns
# dict_keys objects from dictionary .keys() method.
if isinstance(output, collections.abc.KeysView):
output = list(output)

if isinstance(output, str):
exprs = [cls.strip_delimiter(expr) for expr in cls._regex_parser.findall(output)]

Expand Down
4 changes: 3 additions & 1 deletion orquesta/expressions/yql.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ def evaluate(cls, text, data=None):
stripped = cls.strip_delimiter(expr)
result = cls._engine(stripped).evaluate(context=ctx)

if inspect.isgenerator(result):
# Fix #247 by casting set objects to list. YAQL returns
# set objects from dictionary .keys() method.
if inspect.isgenerator(result) or isinstance(result, set):
result = list(result)

if isinstance(result, str):
Expand Down
2 changes: 1 addition & 1 deletion orquesta/specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import collections
import collections.abc
import inspect
import json
import jsonschema
Expand Down
4 changes: 2 additions & 2 deletions orquesta/tests/unit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def assert_graph_equal(self, wf_graph, expected_wf_graph):
self.assertListEqual(wf_graph_attrs, expected_wf_graph_attrs)


class WorkflowSpecTest(unittest.TestCase):
class WorkflowSpecTest(unittest.TestCase, metaclass=abc.ABCMeta):
spec_module_name = "mock"

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -141,7 +141,7 @@ def assert_compose_to_wf_ex_graph(self, wf_name, expected_wf_ex_graph):
self.assert_graph_equal(wf_ex_graph, expected_wf_ex_graph)


class WorkflowConductorTest(WorkflowComposerTest, metaclass=abc.ABCMeta):
class WorkflowConductorTest(WorkflowComposerTest):
def format_task_item(
self,
task_id,
Expand Down

0 comments on commit 7a6c643

Please sign in to comment.