Skip to content

Commit e628e3c

Browse files
committed
CallbackRegistrar: fix injected correlation hooks
Bug introduced in b0443cd
1 parent 7059b25 commit e628e3c

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

dp3/common/callback_registrar.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from functools import partial, wraps
33
from logging import Logger
4-
from typing import Callable, Union
4+
from typing import Any, Callable, Union
55

66
from pydantic import BaseModel
77

@@ -18,6 +18,16 @@
1818
from dp3.task_processing.task_executor import TaskExecutor
1919

2020

21+
def _drop_master(h: Callable[[str, dict], Any]) -> Callable[[str, dict, dict], Any]:
22+
"""Ignore master record for this variant of the hook"""
23+
24+
def wrapped(e: str, s: dict, _m: dict):
25+
return h(e, s)
26+
27+
wraps(h)(wrapped)
28+
return wrapped
29+
30+
2131
def write_datapoints_into_record(model_spec: ModelSpec, tasks: list[DataPointTask], record: dict):
2232
eid = record["eid"]
2333
for task in tasks:
@@ -237,8 +247,11 @@ def register_on_entity_creation_hook(
237247
if refresh is not None:
238248
if may_change is None:
239249
raise ValueError("'may_change' must be specified if 'refresh' is specified")
250+
correlation_hook = partial(
251+
on_entity_creation_in_snapshots, self.model_spec, refresh, hook
252+
)
240253
self._snap_shooter.register_correlation_hook(
241-
partial(on_entity_creation_in_snapshots, self.model_spec, refresh, hook),
254+
_drop_master(correlation_hook),
242255
entity,
243256
[],
244257
may_change,
@@ -294,9 +307,9 @@ def register_on_new_attr_hook(
294307
return
295308
if may_change is None:
296309
raise ValueError("'may_change' must be specified if 'refresh' is specified")
297-
310+
correlation_hook = partial(on_attr_change_in_snapshots, self.model_spec, refresh, hook)
298311
self._snap_shooter.register_correlation_hook(
299-
partial(on_attr_change_in_snapshots, self.model_spec, refresh, hook),
312+
_drop_master(correlation_hook),
300313
entity,
301314
[[attr]],
302315
may_change,
@@ -368,14 +381,8 @@ def register_correlation_hook(
368381
Raises:
369382
ValueError: On failure of specification validation.
370383
"""
371-
372-
# Ignore master record for this variant of the hook
373-
@wraps(hook)
374-
def wrapped_hook(e: str, s: dict, _m: dict):
375-
return hook(e, s)
376-
377384
self._snap_shooter.register_correlation_hook(
378-
wrapped_hook, entity_type, depends_on, may_change
385+
_drop_master(hook), entity_type, depends_on, may_change
379386
)
380387

381388
def register_correlation_hook_with_master_record(

0 commit comments

Comments
 (0)