fix: unwrap single-key kaizen resolver payloads in resolve_context

When discover_kaizen_projects returns {"projects": [...]} bound to
context.projects, for_each can iterate the list directly. Multi-key
summaries (e.g. repo SBOM bulk) remain unchanged.
This commit is contained in:
2026-06-18 08:11:09 +02:00
parent 517bf9c133
commit 9a72c9f210
2 changed files with 60 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ from __future__ import annotations
import uuid
from datetime import datetime, timezone
from typing import Any
from sqlalchemy import select
from sqlalchemy.dialects.postgresql import insert as pg_insert
@@ -52,6 +53,18 @@ def _get_session_factory() -> async_sessionmaker[AsyncSession]:
return _session_factory
def _bind_resolver_result(bind_key: str, result: Any) -> Any:
"""Unwrap single-key resolver payloads when the key matches bind_key.
Resolvers such as ``discover_kaizen_projects`` return ``{"projects": [...]}``
while definitions bind to ``context.projects`` and iterate ``for_each:
context.projects``. Multi-key summaries (e.g. repo SBOM bulk) stay intact.
"""
if isinstance(result, dict) and len(result) == 1 and bind_key in result:
return result[bind_key]
return result
# ── Activities ─────────────────────────────────────────────────────────────────
@activity.defn
@@ -139,7 +152,8 @@ async def resolve_context(
continue
try:
snapshot[bind_key] = resolver_cls().resolve(query, None, params)
resolved = resolver_cls().resolve(query, None, params)
snapshot[bind_key] = _bind_resolver_result(bind_key, resolved)
except Exception as exc:
if required:
raise ApplicationError(