https://dagster.io/ logo
Title
s

Stephen Bailey

03/12/2023, 11:38 AM
What is the path to setting optional config fields in the new Config class? My instinct was to set a
None
default but that still results in a requirement to specify a string.
from dagster import Config, asset, RunConfig, materialize

class AssetConfig(Config):
    name: str = "stephen"
    optional_adverb: str = None

@asset
def foo(config: AssetConfig) -> str:
    msg = f"{config.name} is {config.optional_adverb} cool."
    print(msg)
    return msg

# these should be valid configs
materialize([foo], run_config=RunConfig({"foo": AssetConfig(optional_adverb="really")}))
materialize([foo], run_config=RunConfig({"foo": AssetConfig()}))
error
Error 1: Value at path root:ops:foo:config:optional_adverb must not be None. Expected "(String | { env: String })"
:dagster-bot-resolve: 1
c

Chris Zubak-Skees

03/12/2023, 12:51 PM
If it's based on Pydantic, maybe `
from typing import Optional
...
class AssetConfig(Config):
    optional_adverb: Optional[str]
v

Vinnie

03/13/2023, 7:53 AM
I think what Chris said works but I haven’t used it on my end; I do have a few cases using
pydantic.Field
though:
class MyConfig(Config):
    my_required_config: str = Field(..., description="Some description")
    my_optional_config: str = Field(None, description="Some other description")
s

Stephen Bailey

03/13/2023, 2:37 PM
Does that work in your case @Vinnie, when you pass a RunConfig that uses the None default? I'm not seeing either of those approaches work for some reason.
from dagster import Config, asset, RunConfig, materialize

from typing import Optional
from pydantic import Field

class AssetConfig(Config):
    name: str = "stephen"
    optional_adverb: str = Field(None)

@asset
def foo(config: AssetConfig) -> str:
    msg = f"{config.name} is {config.optional_adverb} cool."
    print(msg)
    return msg

# these should be valid configs
materialize([foo], run_config=RunConfig({"foo": AssetConfig()}))
v

Vinnie

03/13/2023, 2:39 PM
Ah, I haven’t tested this specifically since I usually preconfigure with
@graph(config=config)
to be able to materialize without supplying extra config
👍 1
b

ben

03/14/2023, 12:46 AM
Hi Stephen, thanks for calling this out! It looks like a bug with our
RunConfig
adapter’s conversion to the underlying Dagster config
❤️ 1
https://github.com/dagster-io/dagster/pull/12933 should fix, which we’ll roll out with this week’s release
🙌 1
:rainbow-daggy: 1
s

Stephen Bailey

03/14/2023, 1:01 PM
thanks ben!