Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions pyegeria/view/_output_format_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import warnings
from pathlib import Path
from typing import Dict, List, Optional, Union, Any
from pydantic import BaseModel, Field, field_validator, model_validator
from pydantic import BaseModel, Field, PrivateAttr, field_validator, model_validator
from loguru import logger
__all__ = [
'Column',
Expand Down Expand Up @@ -262,28 +262,35 @@ class ActionParameter(BaseModel):
analytic_function: Optional[str] = None
analytic_spec_params: Dict[str, Any] = Field(default_factory=dict)

@model_validator(mode="before")
_dropped_binders: List[str] = PrivateAttr(default_factory=list)

@model_validator(mode="wrap")
@classmethod
def _drop_deprecated_binders(cls, values):
def _drop_deprecated_binders(cls, values, handler):
"""Accept and ignore the removed `analytic_binders` key for one release (RS-W2-3 PR-B).

An empty mapping (what older generated specs serialise) is dropped silently. A non-empty
one is dropped with a DeprecationWarning and a log warning naming the parameters: the
routine must declare them as `inputs` instead, or its call will lack them.
routine must declare them as `inputs` instead, or its call will lack them. The names are
kept on the model (`_dropped_binders`) so the spec resolver can report them as a warning.
"""
names: List[str] = []
if isinstance(values, dict) and "analytic_binders" in values:
values = dict(values)
binders = values.pop("analytic_binders")
if binders:
names = ", ".join(sorted(binders)) if isinstance(binders, dict) else repr(binders)
names = sorted(binders) if isinstance(binders, dict) else [repr(binders)]
message = (
f"analytic_binders is no longer supported and is ignored (binders for: {names}). "
f"analytic_binders is no longer supported and is ignored (binders for: {', '.join(names)}). "
f"Declare these arguments as the routine's inputs (reader:<name>, viewer, subject, "
f"egeria_client:<Class>); the environment's role supply provides them. "
f"The key will be refused in a later release.")
warnings.warn(message, DeprecationWarning, stacklevel=2)
logger.warning(message)
return values
model = handler(values)
if names:
model._dropped_binders = names
return model

@model_validator(mode="before")
@classmethod
Expand Down
17 changes: 17 additions & 0 deletions pyegeria/view/spec_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ def _as_dict(spec: Any) -> Dict[str, Any]:
return dict(spec or {})


BINDERS_DEPRECATED_PREFIX = "deprecated: analytic_binders ignored"


def _dropped_binders(spec: Any, action: Dict[str, Any]) -> List[str]:
"""The parameter names of a non-empty `analytic_binders` the spec carried: noted on the loaded
ActionParameter by its shim, or still in the action when `spec` is a plain dict."""
names = list(getattr(getattr(spec, "action", None), "_dropped_binders", None) or [])
binders = action.get("analytic_binders")
if binders and not names:
names = sorted(binders) if isinstance(binders, dict) else [repr(binders)]
return names


def _target_type_name(data: Dict[str, Any]) -> Optional[str]:
"""Egeria's property name (`target_type_name`), with `target_type` read as its alias."""
return data.get("target_type_name") or data.get("target_type")
Expand Down Expand Up @@ -413,6 +426,10 @@ def fail(check: int, sentence: str) -> None:
f"Spec '{name}' cannot run on its own: it has no action, so it formats elements another call "
f"fetched (it is a detail or a command's output format)."])

dropped = _dropped_binders(spec, action)
if dropped:
warns.append(f"{BINDERS_DEPRECATED_PREFIX} (binders for: {', '.join(dropped)}); declare these "
f"arguments as the routine's inputs, which the environment's role supply provides")
out: Dict[str, Any] = {"stages": [], "params": [], "seeds": [], "role_inputs": [], "tile_safe": None,
"admission": {}}
has_find = bool(action.get("function"))
Expand Down
65 changes: 65 additions & 0 deletions tests/micro-tests/test_rs_w2_4_binder_deprecation_warning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""RS-W2-4 PR-0 (owner decision O1-a, 2026-11-08): a spec that still carries a non-empty
`analytic_binders` key reports it among the resolver's warnings, with a stable prefix the
Portal tags on. The PR-B shim still drops the key; an empty key stays silent.
"""
import warnings

import pytest

from pyegeria.view import spec_resolver as sr
from pyegeria.view._output_format_models import FormatSet

PREFIX = "deprecated: analytic_binders ignored (binders for: "


def _spec_dict(binders):
return {"heading": "W24-Binder", "description": "probe", "target_type": "Referenceable",
"action": {"analytic_function": "count_elements", "analytic_binders": binders},
"formats": [{"types": ["DICT"], "attributes": []}]}


def _binder_warnings(result):
return [w for w in result.warnings if w.startswith(sr.BINDERS_DEPRECATED_PREFIX)]


def test_the_prefix_is_the_stable_one_the_portal_matches():
assert sr.BINDERS_DEPRECATED_PREFIX == "deprecated: analytic_binders ignored"


def test_a_loaded_spec_with_a_non_empty_binder_carries_the_warning():
with pytest.warns(DeprecationWarning):
spec = FormatSet.model_validate(_spec_dict({"reader": "x.Reader", "mgr": "os.getcwd"}))
assert "analytic_binders" not in spec.model_dump()["action"]
found = _binder_warnings(sr.resolve(spec, "W24-Binder", registry_names=set()))
assert len(found) == 1
assert found[0].startswith(PREFIX + "mgr, reader)")


def test_the_note_survives_a_copy_of_the_spec():
with pytest.warns(DeprecationWarning):
spec = FormatSet.model_validate(_spec_dict({"ods": "x.OdsReader"}))
copied = spec.model_copy(deep=True)
assert _binder_warnings(sr.resolve(copied, "W24-Binder", registry_names=set()))[0].startswith(
PREFIX + "ods)")


def test_a_plain_dict_spec_with_a_binder_carries_the_warning():
found = _binder_warnings(sr.resolve(_spec_dict({"ods": "x.OdsReader"}), "W24-Binder", registry_names=set()))
assert len(found) == 1 and found[0].startswith(PREFIX + "ods)")


@pytest.mark.parametrize("empty", [{}, None, []])
def test_an_empty_binder_gives_no_warning(empty):
with warnings.catch_warnings():
warnings.simplefilter("error")
spec = FormatSet.model_validate(_spec_dict(empty))
assert spec.action._dropped_binders == []
assert _binder_warnings(sr.resolve(spec, "W24-Binder", registry_names=set())) == []
assert _binder_warnings(sr.resolve(_spec_dict(empty), "W24-Binder", registry_names=set())) == []


def test_no_registered_spec_carries_the_warning():
"""No built-in, demo or generated spec sets a non-empty binder (the 274 empty keys stay silent)."""
results = sr.resolve_all(refresh=True)
assert results
assert {label for label, r in results.items() if _binder_warnings(r)} == set()
Loading