Skip to content

API Reference parrot_formdesigner.services.submissions

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

parrot_formdesigner.services.submissions

View source

Form submission persistence service.

Provides the FormSubmission Pydantic model and FormSubmissionStorage class for persisting form submission records to a PostgreSQL table. Storage is local-first — data is always saved before optional forwarding to external endpoints.

Schema, table name, and tenant are configurable. The default schema is navigator (NOT public) and the default table is form_data (renamed from the original form_submissions). Pass tenant at construction or per-call to target a per-tenant schema such as epson.form_data.

Attribute CORE_METADATA_COLUMNS

Type: tuple[str, ...]

Attribute DEFAULT_SCHEMA

Attribute DEFAULT_TABLE

Class DuplicateResponse

store_guarded refused: another response of the form has the same key value (FEAT-730).

Parameter Type Default Description
field_id str

Class FormSubmission

Record of a single form data submission.

Fields:

Field Type Default Description
submission_id str Unique identifier for this submission.
form_uid uuid.UUID Immutable UUID of the parent form (FEAT-389). Required — every submission must reference its form by stable identity, since form_id (the slug) may be renamed after the fact.
form_id str ID (slug) of the form that was submitted. Kept for human-readable queries; not stable across a form rename.
form_version str Version of the form at the time of submission.
data dict[str, Any] The validated (sanitized) submission data.
is_valid bool Whether the submission passed form validation.
forwarded bool False Whether the submission was forwarded to an external endpoint.
forward_status int | None None HTTP status code from the forwarding request (if any).
forward_error str | None None Error message from failed forwarding (if any).
created_at datetime UTC timestamp when the submission was created.
tenant str | None None Optional tenant slug. When set, FormSubmissionStorage uses it to resolve the Postgres schema where the submission is stored. None falls back to the storage's default schema.
user_id str | None None Promoted metadata column — authenticated user identifier.
username str | None None Promoted metadata column — authenticated username.
org_id int | None None Promoted metadata column — authenticated organization ID.
submitted_at datetime | None None Promoted metadata column — wall-clock moment the form left the client. Distinct from created_at (which is the DB-insert moment).
ip str | None None Promoted metadata column — submitter IP address.
user_agent str | None None Promoted metadata column — submitter User-Agent header.
locale str | None None Promoted metadata column — BCP-47 locale (e.g. en-US).
root_submission_id str | None None Revision-chain anchor — the submission_id of the first revision in the chain. Equals this record's own submission_id on revision 1. None on legacy rows, which readers treat as a single-revision chain.
revision int | None None 1-based position within the revision chain. None on legacy rows.
context dict[str, Any] | None None Optional per-revision audit context (free-form JSONB), e.g. geofence status, GPS coordinates, and a post-visit flag.
extra_data dict[str, Any] | None None Captured undeclared submission keys, verbatim (FEAT-458). None when the policy was not keep, or when keep was active and no extras arrived — never {}.

Class FormSubmissionStorage

Persist form submissions in a PostgreSQL table.

Follows the same pattern as PostgresFormStorage: identifier-validated SQL, asyncpg pool management, and an explicit initialize() step that creates the table when the application starts. The target schema must already exist.

Parameter Type Default Description
pool Any An active asyncpg connection pool.
schema str DEFAULT_SCHEMA Postgres schema where the table lives. Default "navigator". Used when no per-call tenant overrides it.
table_name str DEFAULT_TABLE Table name within schema. Default "form_data".
tenant str | None None Optional default tenant slug. When set, every operation without an explicit tenant= kwarg targets <tenant>.<table_name> instead of <schema>.<table_name>.

Method FormSubmissionStorage.attach_pending_uploads

Late-bind the pending-upload registry (FEAT-731). None detaches.

attach_pending_uploads(store: Any) -> None

Parameter Type Default Description
store Any

Method FormSubmissionStorage.initialize

Create the configured submission table if it does not exist.

Idempotent. Targets the default schema unless a tenant is provided (or the instance has a default tenant configured). The schema itself MUST already exist.

Runs the metadata-column ALTER TABLE ... ADD COLUMN IF NOT EXISTS block immediately after the CREATE TABLE so legacy form_data tables pick up the new columns on startup.

initialize(*, tenant: str | None = None) -> None

Parameter Type Default Description
tenant str | None None

Method FormSubmissionStorage.store

Persist a FormSubmission record and return its submission_id.

store(submission: FormSubmission, *, tenant: str | None = None) -> str

Parameter Type Default Description
submission FormSubmission The submission record to insert.
tenant str | None None Optional per-call tenant override. If omitted, falls back to submission.tenant, then the storage's default tenant, then schema.

Returns: str — The submission_id of the persisted record.

Method FormSubmissionStorage.count_responses

Count revision-chain roots of form_uid in the tenant's table.

count_responses(form_uid: uuid.UUID, *, tenant: str | None = None) -> int

Parameter Type Default Description
form_uid uuid.UUID
tenant str | None None

Returns: int

Method FormSubmissionStorage.store_guarded

Lock, count, key-check and INSERT in one transaction.

store_guarded(submission: FormSubmission, *, tenant: str | None = None, max_responses: int | None = None, unique_key_field: str | None = None, unique_value: Any | None = None) -> str

Parameter Type Default Description
submission FormSubmission
tenant str | None None
max_responses int | None None
unique_key_field str | None None
unique_value Any | None None

Returns: str — The submission_id of the persisted record.

Raises:

  • ResponseLimitReached — the form already has max_responses roots.
  • DuplicateResponse — another response has the same key value.

Method FormSubmissionStorage.references_blob

True when any stored submission of form_uid references blob_ref anywhere in data.

references_blob(form_uid: uuid.UUID, blob_ref: str, *, tenant: str | None) -> bool

Parameter Type Default Description
form_uid uuid.UUID
blob_ref str
tenant str | None

Returns: bool

Method FormSubmissionStorage.get_submission

Fetch a single submission by submission_id.

get_submission(submission_id: str, *, tenant: str | None = None) -> FormSubmission | None

Parameter Type Default Description
submission_id str The unique submission identifier to look up.
tenant str | None None Optional per-call tenant override (schema resolution).

Returns: FormSubmission | None — The matching :class:FormSubmission, or None if no row exists.

Method FormSubmissionStorage.list_revisions

Return the full revision chain for a submission, oldest first.

The chain is every row sharing root_submission_id, ordered by revision ASC. Legacy rows written before the revision-chain columns existed have NULL root_submission_id/revision and are therefore single-revision chains reachable only via their own submission_id (use :meth:get_submission for those).

list_revisions(root_submission_id: str, *, tenant: str | None = None) -> list[FormSubmission]

Parameter Type Default Description
root_submission_id str The chain anchor (revision 1's submission_id).
tenant str | None None Optional per-call tenant override (schema resolution).

Returns: list[FormSubmission] — The chain ordered by revision ascending (empty if none).

Class ResponseLimitReached

store_guarded refused: the form already has >= max_responses root responses (FEAT-730).

Alias is_undefined_table

Re-exported from parrot_formdesigner.services._db_utils.is_undefined_table.

Alias qualified_table

Re-exported from parrot_formdesigner.services._identifiers.qualified_table.

Alias validate_identifier

Re-exported from parrot_formdesigner.services._identifiers.validate_identifier.

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