what is wrong with this code? i keep getting error...
# ask-community
k
what is wrong with this code? i keep getting error and cant figure out why:
Copy code
dagster/_core/workspace/context.py:610: UserWarning: Error loading repository location api.py:dagster._core.errors.DagsterInvalidDefinitionError: resource with key 'feather' required by op 'api_get_list' was not provided. Please provide a <class 'dagster._core.definitions.resource_definition.ResourceDefinition'> to key 'feather', or change the required key to one of the following keys which points to an <class 'dagster._core.definitions.resource_definition.ResourceDefinition'>: ['io_manager']
resources.py:
Copy code
class FeatherManager:
    def __init__(self, directory):
        self.directory = directory
    def get(self, api, assetname):
        filepath = f"{self.directory}/{api}/{assetname}.feather"
        return pd.read_feather(filepath)
    def set(self, api, assetname, df: DataFrame):
        filepath = f"{self.directory}/{api}/{assetname}.feather"
        df.to_feather(filepath)
@resource
def feather_resource(_):
    directory = os.getenv("DATA_FEATHER_ROOT")
    return FeatherManager(directory)

defs = Definitions(
    assets=[
        test_mongo_connection,
        test_redis_connection,
        test_feather_connection,
        test_parquet_connection,
    ],
    resources={
        "mongo": mongo_resource,
        "redis": redis_resource,
        "feather": feather_resource,
        "parquet": parquet_resource,
    },
)
api.py:
Copy code
# other imports ...
from resources import feather_resource
from resources import mongo_resource

@asset(required_resource_keys={"feather"})
def api_get_list(context) -> Output[None]:
    feather = context.resources.feather
    
    # code to make api call and convert to dataframe ...
    
    # write df to feather file
    feather.set("api", "api_get_list", df)
    
    # set metadata on asset
    return Output(
        None,
        metadata={
            "computed_at": datetime.now().isoformat(),
            "count": len(df),
            "tickers_first5": df.head(5).to_json(orient="records")
        }
    )

@repository
def wbrepo():
    return [
        api_get_list
    ]
🤖 1
t
looks like you're double dipping with code locations and repositories. Repositories are deprecated in favor of code locations/definitions. You can fix this by removing the repository you make, and loading thwat asset into the
defs
. You might benefit from looking at our recommended project structure or an example project
k
i am so lost trying to go through the fully featured project. why dont you guys put comments in the python code explaining each line? its a tutorial not a higly optimized production environment. i have no clue what 50% of these lines are doing as a beginner. especially these init files. its doing so many things that interact with each other and im just trying to understand one thing at a time. i did have a few things working (resources of redis, mongo, parquet, feather and some api calls to feather files) but i will try to move my code into this example structure to see if i can get the defs correctly. i’ll hack some more. thanks.
s
Hey Kyle, putting more comments into the example code is a good suggestion, we’ll take that into account as we develop our examples. In the meantime if you’re feeling overwhelmed by looking at full-featured examples I strongly recommend going step by step through the tutorial: https://docs.dagster.io/tutorial
❤️ 1
k
^ i think also putting a link to the docs above sections like this is useful. i just been doing this myself in my own examples to reference when i find them.
Copy code
# DOCS: <https://docs.dagster.io/concepts/code-locations#defining-code-locations>
defs = Definitions(
    assets=defs_assets,
    ##resources=resources_by_deployment_name[deployment_name],
    ##schedules=[core_assets_schedule],
    ##sensors=defs_sensors,
)
thank you box 1