metaflow icon indicating copy to clipboard operation
metaflow copied to clipboard

Exception when running a flow with an optional config

Open svpino opened this issue 7 months ago • 1 comments

Since 2.15.15, you can't run a flow with an optional Config property.

Code to reproduce the issue:

from metaflow import Config, FlowSpec, card, step

class Sample(FlowSpec):
    config = Config("config", default=None)

    @card
    @step
    def start(self):
        self.next(self.end)

    @step
    def end(self):
        pass


if __name__ == "__main__":
    Sample()

Exception trace:

Metaflow 2.15.15 executing Sample for user:vscode
    Internal error
Traceback (most recent call last):
  File "/workspaces/ml.school/.venv/lib/python3.12/site-packages/metaflow/cli.py", line 619, in main
    start(auto_envvar_prefix="METAFLOW", obj=state)
  File "/workspaces/ml.school/.venv/lib/python3.12/site-packages/metaflow/_vendor/click/core.py", line 829, in __call__
    return self.main(args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/ml.school/.venv/lib/python3.12/site-packages/metaflow/_vendor/click/core.py", line 782, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/workspaces/ml.school/.venv/lib/python3.12/site-packages/metaflow/cli_components/utils.py", line 42, in invoke
    return click.Command.invoke(self, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/ml.school/.venv/lib/python3.12/site-packages/metaflow/_vendor/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/ml.school/.venv/lib/python3.12/site-packages/metaflow/_vendor/click/core.py", line 610, in invoke
    return callback(args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/ml.school/.venv/lib/python3.12/site-packages/metaflow/_vendor/click/decorators.py", line 21, in new_func
    return f(get_current_context(), args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/ml.school/.venv/lib/python3.12/site-packages/metaflow/cli.py", line 499, in start
    k: ConfigValue(v)
       ^^^^^^^^^^^^^^
  File "/workspaces/ml.school/.venv/lib/python3.12/site-packages/metaflow/user_configs/config_parameters.py", line 89, in __init__
    self._data = {k: self._construct(v) for k, v in data.items()}
                                                    ^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'items'

This was working on 2.15.14. I reported this issue before (#2191) and it was fixed and closed.

svpino avatar Jun 10 '25 13:06 svpino

Argh -- ok, let me push a fix for that. Fixed a bunch of other issues with configs but introduced a new one. Should be an easy fix. Sorry about that.

romain-intel avatar Jun 11 '25 04:06 romain-intel