I'm very confused with dynamic partitions. I have ...
# ask-community
l
I'm very confused with dynamic partitions. I have one asset that returns a dataframe, and want to iterate over the values of that column to run at most one request for each unique value in that column. Currently I have:
Copy code
@asset
def users() -> pd.DataFrame:
    return pd.read_csv("./data/users.csv").head(4)

@asset_sensor(asset_key=AssetKey("users"))
def user_sensor(context: SensorEvaluationContext, asset_event: EventLogEntry):
    yield RunRequest(partition_key=asset_event.asset_materialization.metadata["partition_key"])
It is very unclear what I'm supposed to do next. I have been hopping around between documentation for sensors, asset sensors, @claire's slack messages, context.cursor, dynamic partitions, and the dynamic partitions example from github and am suuuuuper lost. What do I do next to run a function that receives that new dynamic partition value and writes an asset?
t
Hi! Sorry the experience has you feeling this way, and I appreciate your feedback. Once you've yielded the run request, the assets the
users
asset will kick off a run and you can access the run's partition key with `
Copy code
context.asset_partition_key_for_output()
`, as you would with other partitioned assets. At that point, it's up to the user to decide what the logic is to use that information about the partition themselves. ie. using that key query a database or upsert a record somewhere.