Skip to content

Commit 9ffdbe7

Browse files
rustyconoverclaude
andcommitted
fix: Setting/Secret annotations on an inherited on_bind() reach the subclass
An abstract or generic base class skips the on_bind() scan and records no parameters, and a subclass that does not redefine on_bind() copied that empty result. A Secret() declared once on a shared base's on_bind() was therefore never requested (required_secrets empty) and arrived as None, with no warning. Table and aggregate functions now always read the on_bind() the class actually resolves to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8b4bbf5 commit 9ffdbe7

4 files changed

Lines changed: 98 additions & 6 deletions

File tree

‎tests/test_aggregate_function.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,3 +1125,32 @@ def test_stored_state_is_the_packed_encoding(self) -> None:
11251125
storage = BoundStorage(PackedSumAgg.storage, execution_id)
11261126
stored = storage.state_get(FrameworkNS.AGGREGATE_STATE, BoundStorage.pack_int_key(0))
11271127
assert stored == struct.pack("<q", 42)
1128+
1129+
1130+
class TestInheritedOnBindSecrets:
1131+
"""A Secret() on an aggregate base class's on_bind() reaches its subclasses."""
1132+
1133+
def test_subclass_inherits_on_bind_secret(self) -> None:
1134+
"""The child does not redefine on_bind, and still requests the base's secret."""
1135+
from vgi.arguments import Secret
1136+
from vgi.invocation import BindResponse
1137+
1138+
class _SecretSum(PackedSumAgg):
1139+
class Meta:
1140+
name = "secret_sum"
1141+
1142+
@classmethod
1143+
def on_bind(
1144+
cls,
1145+
params: Any,
1146+
*,
1147+
key: Annotated[dict[str, Any] | None, Secret("s3")] = None,
1148+
) -> BindResponse:
1149+
return super().on_bind(params)
1150+
1151+
class _Child(_SecretSum):
1152+
class Meta:
1153+
name = "secret_sum_child"
1154+
1155+
assert set(_SecretSum._secret_params) == {"key"}
1156+
assert set(_Child._secret_params) == {"key"}

‎tests/test_secret_requirements.py‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,60 @@ def test_missing_type_is_none_then_required_error_on_retry(self) -> None:
213213
retry = SecretsAccessor(batch, is_retry=True)
214214
with pytest.raises(ValueError, match="Required secret 'brave' not found"):
215215
retry.get("brave", required=True)
216+
217+
218+
class TestInheritedOnBindAnnotations:
219+
"""Setting/Secret annotations on a shared base class's on_bind() reach its subclasses."""
220+
221+
def test_generic_base_secret_reaches_subclass(self) -> None:
222+
"""A generic base declaring Secret() on on_bind: the concrete child requests it."""
223+
from typing import Generic, TypeVar
224+
225+
resolve_metadata.cache_clear()
226+
t = TypeVar("t")
227+
228+
class _Base(TableFunctionGenerator[t], Generic[t]):
229+
@classmethod
230+
def on_bind(
231+
cls,
232+
params: BindParams[t],
233+
*,
234+
key: Annotated[dict[str, Any] | None, Secret("congress_gov")] = None,
235+
) -> BindResponse:
236+
return BindResponse(output_schema=pa.schema([pa.field("x", pa.int64())]))
237+
238+
@classmethod
239+
def process(cls, params: Any, state: Any, out: Any) -> None: ...
240+
241+
class _Child(_Base[_Args]):
242+
class Meta:
243+
pass
244+
245+
assert set(_Child._secret_params) == {"key"}
246+
assert _Child.get_metadata().required_secrets == [SecretLookupEntry(secret_type="congress_gov")]
247+
248+
def test_concrete_base_secret_reaches_subclass(self) -> None:
249+
"""A concrete base's on_bind annotations are inherited too."""
250+
resolve_metadata.cache_clear()
251+
252+
class _Base(TableFunctionGenerator[_Args]):
253+
class Meta:
254+
pass
255+
256+
@classmethod
257+
def on_bind(
258+
cls,
259+
params: BindParams[_Args],
260+
*,
261+
key: Annotated[dict[str, Any] | None, Secret("s3", scope="s3://b/")] = None,
262+
) -> BindResponse:
263+
return BindResponse(output_schema=pa.schema([pa.field("x", pa.int64())]))
264+
265+
@classmethod
266+
def process(cls, params: Any, state: Any, out: Any) -> None: ...
267+
268+
class _Child(_Base):
269+
class Meta:
270+
pass
271+
272+
assert _Child.get_metadata().required_secrets == [SecretLookupEntry(secret_type="s3", scope="s3://b/")]

‎vgi/aggregate_function.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,15 @@ def __init_subclass__(cls, **kwargs: object) -> None:
297297
# Parse on_bind() signature for Setting/Secret annotations
298298
from vgi.table_function import _extract_setting_secret_params
299299

300+
# Read the on_bind() this class actually uses, inherited or not: an abstract or
301+
# generic base skips this scan and records no parameters, so copying the base's
302+
# (empty) result dropped every Setting/Secret declared on a shared base on_bind().
300303
on_bind_method = getattr(cls, "on_bind", None)
301-
if on_bind_method is not None and "on_bind" in cls.__dict__:
304+
if on_bind_method is not None:
302305
cls._setting_params, cls._secret_params = _extract_setting_secret_params(on_bind_method)
303306
else:
304-
cls._setting_params = getattr(cls, "_setting_params", {})
305-
cls._secret_params = getattr(cls, "_secret_params", {})
307+
cls._setting_params = {}
308+
cls._secret_params = {}
306309

307310
@classmethod
308311
def on_bind(cls, params: AggregateBindParams, **kwargs: Any) -> BindResponse:

‎vgi/table_function.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,12 +974,15 @@ def __init_subclass__(cls) -> None:
974974
)
975975

976976
# Parse on_bind() signature for Setting/Secret annotations
977+
# Read the on_bind() this class actually uses, inherited or not: an abstract or
978+
# generic base skips this scan and records no parameters, so copying the base's
979+
# (empty) result dropped every Setting/Secret declared on a shared base on_bind().
977980
on_bind_method = getattr(cls, "on_bind", None)
978-
if on_bind_method is not None and "on_bind" in cls.__dict__:
981+
if on_bind_method is not None:
979982
cls._setting_params, cls._secret_params = _extract_setting_secret_params(on_bind_method)
980983
else:
981-
cls._setting_params = getattr(cls, "_setting_params", {})
982-
cls._secret_params = getattr(cls, "_secret_params", {})
984+
cls._setting_params = {}
985+
cls._secret_params = {}
983986

984987
@final
985988
@staticmethod

0 commit comments

Comments
 (0)