I have an `asset, job, and schedule` defined almos...
# ask-community
d
I have an
asset, job, and schedule
defined almost exactly according to the partitioned asset tutorials and I'm getting the following error:
dagster._core.errors.DagsterInvariantViolationError: Cannot access partition_key for a non-partitioned run
. Code below.
🤖 1
dagster bot responded by community 1
asset:
Copy code
@asset(
    required_resource_keys={"duckdb"},
    partitions_def=fund_structure_partition,
)
def my_asset(context):
  context.partition_key
  ...
j
Can you copy the configuration of the job and schedule too please?
Try
context.asset_partition_key_for_output()
d
job:
Copy code
asset_job = define_asset_job(
    "asset",
    selection=["group/my_asset"],
    partitions_def=fund_structure_partition,
)
yeah, I tried that first. had the same error
j
selection=["group/asset"],
should point to the asset name. if that case
group/my_asset
I think.
d
oh, right it does. just a typo on my part
Copy code
my_asset_schedule = ScheduleDefinition(
    job=asset_job,
    cron_schedule="*/5 * * * *",
    default_status=DefaultScheduleStatus.RUNNING,
)
j
Ohh so probably the schedule. Try this.
Copy code
my_asset_schedule = build_schedule_from_partitioned_job(
    asset_job,
    default_status=DefaultScheduleStatus.RUNNING,
)
I think you need a partitionned schedule in order to run a partition job. I can be wrong, be using
build_schedule_from_partitioned_job()
with all my assets works fine.
d
oh, hmm
fund_structure_partition = StaticPartitionsDefinition(list(FUND_STRUCTURE.keys()))
so, I think
build_schedule_from_partitioned_job
only works for `TimeWindowPartition`s
j
When I work with Static Partitions I usually issue run request directly instead of using
ScheduleDefinition
. Looking at the documentation event with static partitions they configure it by issuing
RunRequest
so I think you should try this. https://docs.dagster.io/concepts/partitions-schedules-sensors/partitions#creating-schedules-from-partitioned-jobs https://docs.dagster.io/concepts/partitions-schedules-sensors/schedules#schedules-that-provide-custom-run-config-and-tags
This is the end of my knowledge in static partition jobs. Hope this worked. If not someone from Dagster will surely answer this thread soon. 🙂