https://dagster.io/ logo
#ask-community
Title
# ask-community
l

Leo Qin

08/23/2023, 10:11 PM
I'm missing something about how sensor cursors work... any ideas what?? I have a multi-asset sensor that listens on a set of assets, and if ALL of them materialize, I would like to trigger a function and/or a run request. Code below... what's happening, however, is that when the sensor is evaluating, the function is executing with every tick once the monitored assets have been materialized exactly once each, and it's because rows are returned from
context.latest_materialization_records_by_key
even though i call
advance_all_cursors
and no materialization events for the monitored assets have occured. I would have expected that
latest_materialization_record_by_key
would return nothing if no materialization events have happened... or at least that is what the documentation says should be happening....
Copy code
def sensor(context: MultiAssetSensorEvaluationContext):
        asset_events = context.latest_materialization_records_by_key()
        if all(asset_events.values()):
            context.advance_all_cursors()
            if sensor_fn:
                sensor_fn(context)
            if request_assets or jobs:
                return RunRequest()
        elif any(asset_events.values()):
            materialized_asset_key_strs = [
                key.to_user_string() for key, value in asset_events.items() if value
            ]
            not_materialized_asset_key_strs = [
                key.to_user_string() for key, value in asset_events.items() if not value
            ]
            return SkipReason(
                f"Observed materializations for {materialized_asset_key_strs}, "
                f"but not for {not_materialized_asset_key_strs}"
            )
14 Views