Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot have condition on edge with python >= 3.8 #165

Open
vlagorsse opened this issue Sep 26, 2022 · 3 comments
Open

Cannot have condition on edge with python >= 3.8 #165

vlagorsse opened this issue Sep 26, 2022 · 3 comments

Comments

@vlagorsse
Copy link
Contributor

vlagorsse commented Sep 26, 2022

Issue description:

When running the flow commited on 8c7c4c6 with python 3.8, I got the following stack trace:

$ PYTHONPATH=/home/vincent/project/selinon selinon-cli execute --flow-name flow --node-args '{"foo": "bar"}'
Traceback (most recent call last):
  File "/home/vincent/project/selinon/env/bin/selinon-cli", line 8, in <module>
    sys.exit(cli())
  File "/home/vincent/project/selinon/env/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/vincent/project/selinon/env/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/vincent/project/selinon/env/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/vincent/project/selinon/env/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/vincent/project/selinon/env/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/vincent/project/selinon/selinon/cli.py", line 170, in execute
    executor = Executor(nodes_definition, flow_definitions,
  File "/home/vincent/project/selinon/selinon/executor/executor.py", line 81, in __init__
    Config.set_config_yaml(nodes_definition, flow_definitions,
  File "/home/vincent/project/selinon/selinon/config.py", line 152, in set_config_yaml
    cls.set_config_py(config_py)
  File "/home/vincent/project/selinon/selinon/config.py", line 128, in set_config_py
    config_module = runpy.run_path(config_code)
  File "/home/vincent/.pyenv/versions/3.8.10/lib/python3.8/runpy.py", line 264, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
  File "/home/vincent/.pyenv/versions/3.8.10/lib/python3.8/runpy.py", line 239, in _get_code_from_file
    code = compile(f.read(), fname, 'exec')
  File "/tmp/tmpomuuyx5m", line 144
    return fieldNotEqual(message=db.get('loading'), key='payload', value=)
                                                                         ^
SyntaxError: invalid syntax

On a python3.7 environment, it's working fine:

$ PYTHONPATH=/home/vincent/project/selinon selinon-cli execute --flow-name flow --node-args '{"foo": "bar"}'
$

Removing the condition makes also the flow pass on python3.8

@fridex
Copy link
Member

fridex commented Sep 27, 2022

Hi @vlagorsse, thanks for the report. It looks like there is something fishy with config generation. Could you try keeping the generated config by supplying --keep-config-py and see what is wrong in it? Thanks!

@vlagorsse
Copy link
Contributor Author

tmpvd5k0262.txt
Here it is - I had to rename it with .txt extension since otherwise it would not be accepted by github.

@vlagorsse
Copy link
Contributor Author

Hi @fridex ,

I've spent some time to investigate this, it seems that in python 3.8, function keywords are returned being Constant while in 3.7 it was Str. Therefore, codegen seems to not handle this case when we want to generate source code.

I've overriden visit_Constant of NodeVisitor, but I don't know if this approach is correct, basically if every Constant type could be represented the way I've done.

To have a look to the patch I made on codegen, you can check it out here: https://github.com/vlagorsse/codegen/tree/add_constant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants