nicc777 / py-animus

A python based plugable and extensible manifest processing system
GNU General Public License v3.0
0 stars 0 forks source link

Set initial value for `executions_per_manifest_instance` in `ManifestManager` when parsing manifests #50

Closed nicc777 closed 1 year ago

nicc777 commented 1 year ago

Describe the bug

Under certain runtime scenarios an exception can result:

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "<stripped>/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "<stripped>/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "<stripped>/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "<stripped>/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "<stripped>/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "<stripped>/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "$PWDpy-animus-extensions/templates/utils/factory/animus-extension-template.py", line 141, in <module>
    run_main()
  File "$PWDpy-animus-extensions/venv/lib/python3.10/site-packages/py_animus/py_animus.py", line 116, in run_main
    main(command=command, cli_args=cli_args, logger=get_logger())
  File "$PWDpy-animus-extensions/venv/lib/python3.10/site-packages/py_animus/py_animus.py", line 99, in main
    apply_command(vc, mm, logger)
  File "$PWDpy-animus-extensions/venv/lib/python3.10/site-packages/py_animus/py_animus.py", line 49, in apply_command
    mm.apply_manifest(name=name)
  File "$PWDpy-animus-extensions/venv/lib/python3.10/site-packages/py_animus/manifest_management.py", line 877, in apply_manifest
    if manifest_instance.metadata['executeOnlyOnceOnApply'] is True and self.executions_per_manifest_instance[manifest_instance.metadata['name']] > 0:
KeyError: 'cli-input-prompt-v1'

To Reproduce

n/a

Expected behavior

executions_per_manifest_instance property in ManifestManager should already contain the name of the manifest being executed

Development Environment (please complete the following information):

Additional context

    def parse_manifest(self, manifest_data: dict):
        manifest_data = dict((k.lower(), v) for k,v in manifest_data.items())   # Convert first level keys to lower case
        version = None
        if 'version' in manifest_data:
            version = manifest_data['version']
        class_instance_copy = copy.deepcopy(self.get_manifest_class_by_kind(kind=manifest_data['kind'], version=version))
        # NEW code below
        if class_instance_copy.metadata['name'] not in self.executions_per_manifest_instance:
            self.executions_per_manifest_instance[class_instance_copy.metadata['name']] = 0