What is the path to setting optional config fields...
# dagster-feedback
s
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.
Copy code
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
Copy code
Error 1: Value at path root:ops:foo:config:optional_adverb must not be None. Expected "(String | { env: String })"
🤖 1
c
If it's based on Pydantic, maybe `
Copy code
from typing import Optional
...
class AssetConfig(Config):
    optional_adverb: Optional[str]
v
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:
Copy code
class MyConfig(Config):
    my_required_config: str = Field(..., description="Some description")
    my_optional_config: str = Field(None, description="Some other description")
s
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.
Copy code
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
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
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
🌈 1
s
thanks ben!