def _resolve_bound_config(solid_config: Any, solid_def: SolidDefinition) -> Any: """Validate config against config schema, and return validated config.""" from dagster.config.validate import process_config # Config processing system expects the top level config schema to be a dictionary, but solid # config schema can be scalar. Thus, we wrap it in another layer of indirection. outer_config_shape = Shape({"config": solid_def.get_config_field()}) config_evr = process_config( outer_config_shape, {"config": solid_config} if solid_config else {}) if not config_evr.success: raise DagsterInvalidConfigError( f"Error in config for {solid_def.node_type_str} ", config_evr.errors, solid_config, ) validated_config = cast(Dict, config_evr.value).get("config") mapped_config_evr = solid_def.apply_config_mapping( {"config": validated_config}) if not mapped_config_evr.success: raise DagsterInvalidConfigError( f"Error in config for {solid_def.node_type_str} ", mapped_config_evr.errors, solid_config, ) validated_config = cast(Dict, mapped_config_evr.value).get("config") return validated_config
def _config_mapping_with_default_value( inner_schema: ConfigType, default_config: Dict[str, Any], job_name: str, graph_name: str, ) -> ConfigMapping: if not isinstance(inner_schema, Shape): check.failed( "Only Shape (dictionary) config_schema allowed on Job ConfigMapping" ) def config_fn(x): return x updated_fields = {} field_aliases = inner_schema.field_aliases for name, field in inner_schema.fields.items(): if name in default_config: updated_fields[name] = Field( config=field.config_type, default_value=default_config[name], description=field.description, ) elif name in field_aliases and field_aliases[name] in default_config: updated_fields[name] = Field( config=field.config_type, default_value=default_config[field_aliases[name]], description=field.description, ) else: updated_fields[name] = field config_schema = Shape( fields=updated_fields, description="run config schema with default values from default_config", field_aliases=inner_schema.field_aliases, ) config_evr = validate_config(config_schema, default_config) if not config_evr.success: raise DagsterInvalidConfigError( f"Error in config when building job '{job_name}' from graph '{graph_name}' ", config_evr.errors, default_config, ) return ConfigMapping(config_fn=config_fn, config_schema=config_schema, receive_processed_config_values=False)
def _config_mapping_with_default_value( inner_schema: ConfigType, default_config: Dict[str, Any], ) -> ConfigMapping: if not isinstance(inner_schema, Shape): check.failed( "Only Shape (dictionary) config_schema allowed on Job ConfigMapping" ) def config_fn(x): return x updated_fields = {} field_aliases = inner_schema.field_aliases for name, field in inner_schema.fields.items(): if name in default_config: updated_fields[name] = Field( config=field.config_type, default_value=default_config[name], description=field.description, ) elif name in field_aliases and field_aliases[name] in default_config: updated_fields[name] = Field( config=field.config_type, default_value=default_config[field_aliases[name]], description=field.description, ) return ConfigMapping( config_fn=config_fn, config_schema=Shape( fields=updated_fields, description= "run config schema with default values from default_config", ), )