diff --git a/kopf/on.py b/kopf/on.py index ccc8c579..ed6f5e4b 100644 --- a/kopf/on.py +++ b/kopf/on.py @@ -146,7 +146,8 @@ def decorator(fn: callbacks.ResourceHandlerFn) -> callbacks.ResourceHandlerFn: fn=fn, id=real_id, field=None, errors=errors, timeout=timeout, retries=retries, backoff=backoff, cooldown=cooldown, labels=labels, annotations=annotations, when=when, - reason=None, initial=True, deleted=deleted, + initial=True, deleted=deleted, requires_finalizer=None, + reason=None, ) real_registry.resource_changing_handlers[real_resource].append(handler) return fn @@ -176,6 +177,7 @@ def decorator(fn: callbacks.ResourceHandlerFn) -> callbacks.ResourceHandlerFn: fn=fn, id=real_id, field=None, errors=errors, timeout=timeout, retries=retries, backoff=backoff, cooldown=cooldown, labels=labels, annotations=annotations, when=when, + initial=None, deleted=None, requires_finalizer=None, reason=causation.Reason.CREATE, ) real_registry.resource_changing_handlers[real_resource].append(handler) @@ -206,6 +208,7 @@ def decorator(fn: callbacks.ResourceHandlerFn) -> callbacks.ResourceHandlerFn: fn=fn, id=real_id, field=None, errors=errors, timeout=timeout, retries=retries, backoff=backoff, cooldown=cooldown, labels=labels, annotations=annotations, when=when, + initial=None, deleted=None, requires_finalizer=None, reason=causation.Reason.UPDATE, ) real_registry.resource_changing_handlers[real_resource].append(handler) @@ -237,8 +240,8 @@ def decorator(fn: callbacks.ResourceHandlerFn) -> callbacks.ResourceHandlerFn: fn=fn, id=real_id, field=None, errors=errors, timeout=timeout, retries=retries, backoff=backoff, cooldown=cooldown, labels=labels, annotations=annotations, when=when, + initial=None, deleted=None, requires_finalizer=bool(not optional), reason=causation.Reason.DELETE, - requires_finalizer=bool(not optional), ) real_registry.resource_changing_handlers[real_resource].append(handler) return fn @@ -270,6 +273,7 @@ def decorator(fn: callbacks.ResourceHandlerFn) -> callbacks.ResourceHandlerFn: fn=fn, id=real_id, field=real_field, errors=errors, timeout=timeout, retries=retries, backoff=backoff, cooldown=cooldown, labels=labels, annotations=annotations, when=when, + initial=None, deleted=None, requires_finalizer=None, reason=None, ) real_registry.resource_changing_handlers[real_resource].append(handler) @@ -295,6 +299,7 @@ def decorator(fn: callbacks.ResourceHandlerFn) -> callbacks.ResourceHandlerFn: fn=fn, id=real_id, field=None, errors=None, timeout=None, retries=None, backoff=None, cooldown=None, labels=labels, annotations=annotations, when=when, + initial=None, deleted=None, requires_finalizer=None, reason=None, ) real_registry.resource_watching_handlers[real_resource].append(handler) @@ -355,6 +360,7 @@ def decorator(fn: callbacks.ResourceHandlerFn) -> callbacks.ResourceHandlerFn: fn=fn, id=real_id, field=None, errors=errors, timeout=timeout, retries=retries, backoff=backoff, cooldown=cooldown, labels=labels, annotations=annotations, when=when, + initial=None, deleted=None, requires_finalizer=None, reason=None, ) real_registry.append(handler) diff --git a/kopf/reactor/handlers.py b/kopf/reactor/handlers.py index 6aba37a9..b8d20973 100644 --- a/kopf/reactor/handlers.py +++ b/kopf/reactor/handlers.py @@ -46,7 +46,7 @@ def __getattribute__(self, name: str) -> Any: @dataclasses.dataclass class ActivityHandler(BaseHandler): fn: callbacks.ActivityHandlerFn # type clarification - activity: Optional[causation.Activity] = None + activity: Optional[causation.Activity] _fallback: bool = False # non-public! @@ -55,12 +55,12 @@ class ResourceHandler(BaseHandler): fn: callbacks.ResourceHandlerFn # type clarification reason: Optional[causation.Reason] field: Optional[dicts.FieldPath] - initial: Optional[bool] = None - deleted: Optional[bool] = None # used for mixed-in (initial==True) @on.resume handlers only. - labels: Optional[bodies.Labels] = None - annotations: Optional[bodies.Annotations] = None - when: Optional[callbacks.WhenHandlerFn] = None - requires_finalizer: Optional[bool] = None + initial: Optional[bool] + deleted: Optional[bool] # used for mixed-in (initial==True) @on.resume handlers only. + labels: Optional[bodies.Labels] + annotations: Optional[bodies.Annotations] + when: Optional[callbacks.WhenHandlerFn] + requires_finalizer: Optional[bool] @property def event(self) -> Optional[causation.Reason]: diff --git a/kopf/reactor/handling.py b/kopf/reactor/handling.py index 65aa39b5..65d4f259 100644 --- a/kopf/reactor/handling.py +++ b/kopf/reactor/handling.py @@ -110,6 +110,8 @@ async def execute( handler = handlers_.ResourceHandler( fn=fn, id=real_id, errors=None, timeout=None, retries=None, backoff=None, cooldown=None, + labels=None, annotations=None, when=None, + initial=None, deleted=None, requires_finalizer=None, reason=None, field=None, ) subregistry.append(handler) @@ -121,6 +123,8 @@ async def execute( handler = handlers_.ResourceHandler( fn=fn, id=real_id, errors=None, timeout=None, retries=None, backoff=None, cooldown=None, + labels=None, annotations=None, when=None, + initial=None, deleted=None, requires_finalizer=None, reason=None, field=None, ) subregistry.append(handler) diff --git a/tests/basic-structs/test_handlers.py b/tests/basic-structs/test_handlers.py index 56437c5c..793dee9d 100644 --- a/tests/basic-structs/test_handlers.py +++ b/tests/basic-structs/test_handlers.py @@ -46,8 +46,10 @@ def test_resource_handler_with_all_args(mocker): retries = mocker.Mock() backoff = mocker.Mock() initial = mocker.Mock() + deleted = mocker.Mock() labels = mocker.Mock() annotations = mocker.Mock() + when = mocker.Mock() requires_finalizer = mocker.Mock() handler = ResourceHandler( fn=fn, @@ -60,8 +62,10 @@ def test_resource_handler_with_all_args(mocker): backoff=backoff, cooldown=None, # deprecated, but still required initial=initial, + deleted=deleted, labels=labels, annotations=annotations, + when=when, requires_finalizer=requires_finalizer, ) assert handler.fn is fn @@ -73,8 +77,10 @@ def test_resource_handler_with_all_args(mocker): assert handler.retries is retries assert handler.backoff is backoff assert handler.initial is initial + assert handler.deleted is deleted assert handler.labels is labels assert handler.annotations is annotations + assert handler.when is when assert handler.requires_finalizer is requires_finalizer with pytest.deprecated_call(match=r"use handler.reason"): diff --git a/tests/basic-structs/test_handlers_deprecated_cooldown.py b/tests/basic-structs/test_handlers_deprecated_cooldown.py index b9dc5a96..e534569f 100644 --- a/tests/basic-structs/test_handlers_deprecated_cooldown.py +++ b/tests/basic-structs/test_handlers_deprecated_cooldown.py @@ -47,8 +47,10 @@ def test_resource_handler_with_deprecated_cooldown_instead_of_backoff(mocker): retries = mocker.Mock() backoff = mocker.Mock() initial = mocker.Mock() + deleted = mocker.Mock() labels = mocker.Mock() annotations = mocker.Mock() + when = mocker.Mock() requires_finalizer = mocker.Mock() with pytest.deprecated_call(match=r"use backoff="): @@ -63,8 +65,10 @@ def test_resource_handler_with_deprecated_cooldown_instead_of_backoff(mocker): backoff=None, cooldown=backoff, # deprecated, but still required initial=initial, + deleted=deleted, labels=labels, annotations=annotations, + when=when, requires_finalizer=requires_finalizer, ) @@ -77,6 +81,8 @@ def test_resource_handler_with_deprecated_cooldown_instead_of_backoff(mocker): assert handler.retries is retries assert handler.backoff is backoff assert handler.initial is initial + assert handler.deleted is deleted assert handler.labels is labels assert handler.annotations is annotations + assert handler.when is when assert handler.requires_finalizer is requires_finalizer diff --git a/tests/registries/conftest.py b/tests/registries/conftest.py index ec67c2af..c87b346a 100644 --- a/tests/registries/conftest.py +++ b/tests/registries/conftest.py @@ -50,5 +50,7 @@ def parent_fn(**_): return ResourceHandler( fn=parent_fn, id=HandlerId('parent_fn'), errors=None, retries=None, timeout=None, backoff=None, cooldown=None, + labels=None, annotations=None, when=None, + initial=None, deleted=None, requires_finalizer=None, reason=None, field=None, )