https://dagster.io/ logo
#ask-community
Title
# ask-community
c

Charles Lariviere

04/11/2022, 2:01 PM
Hey 👋 I’m having trouble testing a
root_input_manager
, specifically getting the config schema to generate default values. Given this root input manager:
Copy code
@root_input_manager(
    input_config_schema={
        "filepath": Field(str, is_required=True),
        "sep": Field(str, default_value=",", is_required=False, description="Delimiter to use."),
    }
)
def csv_to_df(context):
    return pd.read_csv(
        context.config["filepath"],
        sep=context.config.get("sep")
    )
And a test that looks like this:
Copy code
def test_csv_to_df(self):
        manager = csv_to_df(None)
        context = build_input_context(
            config={"filepath": os.path.join(self.fixtures_dir, "csv_to_df.csv")}
        )

        df = manager.load_input(context)
        ...
The
sep
config value remains
None
— the
default_value
defined in the
Field
object does not seem to get compiled. I’m assuming it’s because passing the
config
argument in
build_input_context
overrides whatever method compiles the schema, but I haven’t been successful in finding a workaround. Am I missing something, or is it simply not yet supported given it’s still experimental?
s

sandy

04/11/2022, 3:57 PM
Hey @Charles Lariviere - you're not missing something. I filed an issue to track this problem: https://github.com/dagster-io/dagster/issues/7379. In the mean time, this might not be a very satisfying solution, but you could always do something like:
Copy code
@root_input_manager(
    input_config_schema={
        "filepath": Field(str, is_required=True),
        "sep": Field(str, is_required=False, description="Delimiter to use."),
    }
)
def csv_to_df(context):
    return pd.read_csv(
        context.config["filepath"],
        sep=context.config.get("sep", ",")
    )
c

Charles Lariviere

04/11/2022, 4:33 PM
Sounds great, thanks @sandy! 🙌
2 Views