Skip to content

API Reference parrot_formdesigner.services.snippets.db_store

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

parrot_formdesigner.services.snippets.db_store

View source

Tenant-scoped, versioned snippet store with a read-through cache.

Mirrors FormRegistry._read_through() (services/registry.py:1035): a cache miss loads from storage and admits the result; ANY storage fault degrades to None (logged, swallowed) rather than raising — resolve_current()'s caller (the resolver closure, TASK-3163) treats None as "no tenant override", which correctly falls back to the platform git snippet via get_form_event()'s existing (tenant, ref) -> (None, ref) precedence.

See spec sdd/specs/formbuilder-custom-code.spec.md §3 Module 5.

Migration: migrations/008_snippet_store.sql (NOTE: the spec's own §3 text says "007" — that number is stale; 007 was already taken by 007_dedupe_duplicate_field_ids.py before this feature's tasks were written. Trust this file, not the spec prose, for the migration number.)

Alias CapabilityManifest

Re-exported from parrot_formdesigner.core.snippets.CapabilityManifest.

Alias CapabilityTier

Re-exported from parrot_formdesigner.core.snippets.CapabilityTier.

Class DbSnippetStore

Read-through cache over the form_snippets table (migration 008).

Parameter Type Default Description
pool _ConnectionPool An asyncpg-pool-shaped connection object (injected — never constructed here, matching FormRegistry's storage injection pattern).
tier3_tier4_tenants TenantTierCapOverrides frozenset() Tenants explicitly allowed to publish tier BROKERED/TOOLKIT bundles. Empty by default (spec Non-Goal: DB snippets capped at tier 2 unless raised).

Method DbSnippetStore.check_tier_cap

Raise if manifest.tier exceeds this tenant's allowed cap.

check_tier_cap(tenant: str, manifest: CapabilityManifest) -> None

Parameter Type Default Description
tenant str
manifest CapabilityManifest

Raises:

  • ValueError — tier is BROKERED/TOOLKIT and tenant is not in tier3_tier4_tenants.

Method DbSnippetStore.get_published

Read-through cache lookup for the current PUBLISHED row.

Fail-soft, mirroring FormRegistry._read_through(): any storage fault is logged and this returns None — never raises.

get_published(*, tenant: str, handler_ref: str) -> SnippetBundle | None

Parameter Type Default Description
tenant str
handler_ref str

Returns: SnippetBundle | None

Method DbSnippetStore.resolve_current

SnippetSourceProtocol implementation.

tenant=None never resolves here — DB snippets are always tenant-scoped by construction; a None tenant is a caller bug.

resolve_current(*, tenant: str | None, handler_ref: str) -> SnippetBundle | None

Parameter Type Default Description
tenant str | None
handler_ref str

Returns: SnippetBundle | None

Method DbSnippetStore.invalidate

Drop this key from the PER-PROCESS cache after a publish/revoke.

FILL IN: cross-process invalidation under multi-worker gunicorn is an explicit "decision deferred to implementation" (spec §8) — this method only handles the current process. TASK-3166 (approval service) must call this after every publish/revoke; a follow-up task should add the cross-process broadcast (listen/notify, TTL, or explicit fan-out) once a deployment topology is chosen.

invalidate(*, tenant: str, handler_ref: str) -> None

Parameter Type Default Description
tenant str
handler_ref str

Method DbSnippetStore.on_startup

aiohttp on_startup — mirrors FormRegistry.on_startup (registry.py:711).

on_startup(app: Any) -> None

Parameter Type Default Description
app Any

Method DbSnippetStore.on_shutdown

aiohttp on_shutdown — mirrors FormRegistry.on_shutdown (registry.py:750).

on_shutdown(app: Any) -> None

Parameter Type Default Description
app Any

Alias SnippetBundle

Re-exported from parrot_formdesigner.core.snippets.SnippetBundle.

Alias SnippetSource

Re-exported from parrot_formdesigner.core.snippets.SnippetSource.

Alias SnippetStatus

Re-exported from parrot_formdesigner.core.snippets.SnippetStatus.

Attribute TenantTierCapOverrides

Attribute logger

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