Skip to content

API Reference parrot_formdesigner.services.callback_registry

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.callback_registry

View source

Tenant-scoped form callback registry for FieldType.REST (mode=callback).

Provides a module-level _CALLBACK_REGISTRY mapping composite keys (tenant_slug_or_None, name) to registered async callback coroutines.

Semantics

  • None is the global sentinel — used for callbacks registered without a tenant. The literal string "None" is rejected at registration time to prevent collisions.
  • Lookup order: (tenant, name) → (None, name) → KeyError. A tenant-specific registration silently shadows (overrides) the global registration for that tenant; other tenants continue to see the global entry.
  • Duplicate (tenant, name) registration raises ValueError. Registrations cannot be silently overridden.

Authorization (who may invoke a callback) is NOT the responsibility of this registry — ACLs live at the handler/resolver boundary.

Pattern

This module mirrors the controls/registry.py shape (module-level dict

  • decorator) but uses a composite (tenant, name) key instead of a plain string key. See spec §7 Tenant-scoped callback registry and §8 Q3 refinement.

Note: RestCallback, RestCallbackInput, and RestCallbackOutput are defined in services/rest_field_resolver.py (TASK-1162). To avoid a circular import, this module accepts and stores plain callables without importing those types at module load time.

Attribute RestCallback

Function get_form_callback

Look up a registered callback with tenant → global fallback.

Resolution order:

  1. (tenant, name) — tenant-specific override.
  2. (None, name) — global fallback.
  3. KeyError if neither exists.

get_form_callback(name: str, *, tenant: str | None = None) -> RestCallback

Parameter Type Default Description
name str Logical callback name (e.g. "planogram_compliance").
tenant str | None None Tenant slug for lookup. Pass None to look up only the global entry (skips the tenant-specific lookup).

Returns: RestCallback — The registered callable.

Raises:

  • KeyError — If no matching callback is found for name.

Function list_form_callbacks

Return all callback keys visible to a tenant.

Returns the union of:

  • Global entries (tenant=None key).
  • Tenant-specific entries for the given tenant (when not None).

Useful for documentation generation and introspection.

list_form_callbacks(tenant: str | None = None) -> list[tuple[str | None, str]]

Parameter Type Default Description
tenant str | None None Tenant slug to include. When None, only global entries are returned.

Returns: list[tuple[str | None, str]] — List of (tenant_or_None, name) keys.

Attribute logger

Function register_form_callback

Decorator that registers an async callback in the form callback registry.

Tenant-scoped: pass tenant="<slug>" for a tenant-specific callback; omit (or pass None) to register a global fallback. Lookup falls back from the tenant-specific entry to the global entry — see module docstring for semantics.

The registered function signature should be::

async def my_callback(
    payload: RestCallbackInput,
    auth_context: AuthContext,
) -> RestCallbackOutput: ...

Example::

@register_form_callback("planogram_compliance")
async def run_compliance(payload, auth_context):
    ...

@register_form_callback("planogram_compliance", tenant="acme")
async def run_acme_compliance(payload, auth_context):
    ...

register_form_callback(name: str, *, tenant: str | None = None) -> Callable[[RestCallback], RestCallback]

Parameter Type Default Description
name str Logical name of the callback (e.g. "planogram_compliance").
tenant str | None None Tenant slug this registration applies to. None registers a global fallback visible to all tenants that lack a specific override for name.

Returns: Callable[[RestCallback], RestCallback] — A decorator that registers the wrapped function and returns it unchanged.

Raises:

  • ValueError — If tenant is the literal string "None" (collision with the global sentinel).
  • ValueError — If (tenant, name) is already registered (no silent override).

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally