|
1 | 1 | import logging |
2 | 2 | from functools import partial, wraps |
3 | 3 | from logging import Logger |
4 | | -from typing import Callable, Union |
| 4 | +from typing import Any, Callable, Union |
5 | 5 |
|
6 | 6 | from pydantic import BaseModel |
7 | 7 |
|
|
18 | 18 | from dp3.task_processing.task_executor import TaskExecutor |
19 | 19 |
|
20 | 20 |
|
| 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 | + |
21 | 31 | def write_datapoints_into_record(model_spec: ModelSpec, tasks: list[DataPointTask], record: dict): |
22 | 32 | eid = record["eid"] |
23 | 33 | for task in tasks: |
@@ -237,8 +247,11 @@ def register_on_entity_creation_hook( |
237 | 247 | if refresh is not None: |
238 | 248 | if may_change is None: |
239 | 249 | 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 | + ) |
240 | 253 | self._snap_shooter.register_correlation_hook( |
241 | | - partial(on_entity_creation_in_snapshots, self.model_spec, refresh, hook), |
| 254 | + _drop_master(correlation_hook), |
242 | 255 | entity, |
243 | 256 | [], |
244 | 257 | may_change, |
@@ -294,9 +307,9 @@ def register_on_new_attr_hook( |
294 | 307 | return |
295 | 308 | if may_change is None: |
296 | 309 | 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) |
298 | 311 | self._snap_shooter.register_correlation_hook( |
299 | | - partial(on_attr_change_in_snapshots, self.model_spec, refresh, hook), |
| 312 | + _drop_master(correlation_hook), |
300 | 313 | entity, |
301 | 314 | [[attr]], |
302 | 315 | may_change, |
@@ -368,14 +381,8 @@ def register_correlation_hook( |
368 | 381 | Raises: |
369 | 382 | ValueError: On failure of specification validation. |
370 | 383 | """ |
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 | | - |
377 | 384 | 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 |
379 | 386 | ) |
380 | 387 |
|
381 | 388 | def register_correlation_hook_with_master_record( |
|
0 commit comments