Hello, I was wondering, given that graph_assets d...
# ask-community
b
Hello, I was wondering, given that graph_assets don't have a config (yet?)... What is the current advised way for translating the graph_asset's partition info to the OP? Is there a way I can access the graph_asset partition info inside the graph function and translate it to the proper OP config? (maybe i'm overlooking an option) I noticed I can access the graph_asset's partition info inside the OP function, but that makes the OP's very polluted if I keep doing this. I'd like to build a nice and clean set of OP's which can then be used to construct various graphs... Somewhere I read that a graph_asset is more similar to a graph than an asset, but it feels wrong using graph_asset's partition definition inside the OP's. (Make the OP code very knowledgable of the context it's called in, which I designwise don't like at that level) I'm looking for my best option. (maybe untill the graph_asset will have a context variable)
Copy code
def some_api_to_read(machine_id, start_date, end_date) -> pd.DataFrame:
    return pd.DataFrame([1,2,3,4])

class ReaderConfig(Config):
    machine_id: str
    start_date: str
    end_date:str

@op
def read_machine_data(context: OpExecutionContext, config: ReaderConfig) -> pd.DataFrame:
    # OP has access to graph partitions, but it already has it's custom config for other jobs 
    <http://context.log.info|context.log.info>(f"graph partition:", {context.partition_time_window[0]}")
    return some_api_to_read(config.machine_id, config.start_date, config.end_date)

@graph_asset(
        partitions_def=MultiPartitionsDefinition(
        {
            "date": DailyPartitionsDefinition(start_date="2023-01-01"),
            "color": StaticPartitionsDefinition(["machine_a", "machine_b", "machine_c"]),
        }
    )
)
def machine_dataset() -> pd.DataFrame:
    read_machine_a_sometime =  read_machine_data.configured({
            "machine_id": "<cannot access partition info here?>",
            "start_date": "<cannot access partition info here?>",
            "end_date": "<cannot access partition info here?>"
        },
        name="read_of_a_machine"
    )

    return read_machine_a_sometime()