Hello - I need help understanding how to use a sof...
# ask-community
m
Hello - I need help understanding how to use a software defined asset in the old @repository type setup that has required resources.... the documents don't have an example where there are configured resources for an asset - it just sorta just lists the assets as something to be returned https://docs.dagster.io/concepts/repositories-workspaces/repositories#defining-a-repository. When I do it - it asks for the resource_defs... fair enough - when I try to run .to_job on the asset definition - it doesn't have that method like a graph does. So how do I give this software defined assets its resource configs? I cannot seem to use define_asset_job because that only works with code locations - not repositories.
j
hey @Matthew Karas you’ll want to use the
with_resources
function
Copy code
@repository 
def my_repo():
    return with_resources([asset1, asset2], resource_defs={"resource_1": resource_1, "resource_2": resource_2})
here’s a link to some old docs https://docs.dagster.io/1.1.5/concepts/resources#providing-resources-to-software-defined-assets
m
Hi @jamie - getting closer -I got it up and running - but when I clicked the launchpad - where do I pass in the asset's configuration? Like when we use to_job on a graph - we can pass in the configuration.
j
you should be able to press Shift and click the Materialize button to open a launchpad to add config
m
Right - but can't we supply a default in the code?
j
how are you setting up the config schema for the assets? a code snippet would be helpful if you can share one! (for context, there are a couple ways to provide config schemas, so i want to make sure i give you an answer that matches your setup)
m
One sec let me sanitize it
Copy code
class MyConfig(Config):
    setting_a: str
    setting_b: str
    setting_c: str

@asset(
    partitions_def=MY_PARTITION_DEF,
    required_resource_keys={"foo", "bar"},
)
def my_asset_i_am_trying_to_get_to_work(
    context, config: MyConfig
) -> ReturnedClass:
	# code goes here
I'm also getting confused on how to provide resources to jobs that are used by a sensor to trigger this software based asset as well... do I use with_resources against the sensor as well?
j
ok since you are using new style config you can set defaults in the MyConfig class!
Copy code
from pydantic import Field 

class MyConfig(Config):
    setting_a: str = Field(default="foo")
    setting_b: str = Field(default="bar")
    setting_c: str # no default
for “jobs that are used by a sensor to trigger this software based asset” are you making that job with the
define_asset_job
function?
m
Thanks - I ended up getting stuff working by using workspace.yaml to have both Definition based and repository based configuration in two separate files. The pedantic defaults were great too.