https://dagster.io/ logo
Title
s

shailesh

05/24/2023, 8:46 AM
Hi All! I am adding sensor for partition asset My sensor code is like below:
def bind_partition_job_sensor(dependent_job: str, sensor_name: str, run_job ) -> SensorDefinition:

	@sensor(name=sensor_name, job=run_job)
	    def run_job_sensor(context):
		run_records = context.instance.get_run_partition_data(
		    runs_filter=RunsFilter(
		        job_name=dependent_job,
		        statuses=[DagsterRunStatus.SUCCESS],
		    )
		)
		if not run_records:
		    return

		for run_record in run_records:
		    yield SensorResult(
		    run_requests=[
		        RunRequest(partition_key=run_record.partition, run_key=run_record.run_id),
		    ]
		    )
	    return run_job_sensor
I am getting below error:
dagster._check.CheckError: Failure condition: When a SensorResult is returned from a sensor, it must be the only object returned.
  File "/usr/local/lib/python3.10/site-packages/dagster/_core/errors.py", line 272, in user_code_error_boundary
    yield
  File "/usr/local/lib/python3.10/site-packages/dagster/_grpc/impl.py", line 375, in get_external_sensor_execution
    return sensor_def.evaluate_tick(sensor_context)
  File "/usr/local/lib/python3.10/site-packages/dagster/_core/definitions/sensor_definition.py", line 708, in evaluate_tick
    check.failed(
  File "/usr/local/lib/python3.10/site-packages/dagster/_check/__init__.py", line 1669, in failed
    raise CheckError(f"Failure condition: {desc}")
Please help me out!🙏
a

Aaron T

05/24/2023, 11:31 AM
Your SensorResult should have an array of RunRequest's. Instead you are yielding multiple sensor results each with 1 run request. Look at the docs, you yield RunRequest's in your for loop and use them in your SensorResult https://docs.dagster.io/concepts/partitions-schedules-sensors/sensors#defining-a-sensor