Skip to content

API Reference parrot_formdesigner.services.pending_uploads

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

parrot_formdesigner.services.pending_uploads

View source

Pending-upload registry (FEAT-731).

One row per blob returned by /file-upload that no stored submission references yet. Cleared by FormSubmissionStorage.store() in the INSERT's transaction; swept by PendingUploadReaper (TTL by form: 48 h public / 7 days otherwise).

Attribute DEFAULT_PUBLIC_FORM_TTL

Attribute DEFAULT_SCHEMA

Attribute DEFAULT_TABLE

Attribute DEFAULT_TTL

Class PendingUpload

One pending (not yet submitted) uploaded blob.

Fields:

Field Type Default Description
blob_ref str
thumbnail_ref str | None None
form_uid uuid.UUID
field_uid uuid.UUID
tenant str
public_form bool
uploaded_at datetime | None None

Class PendingUploadReaper

Delete expired, unreferenced pending uploads for one tenant (FEAT-731). Host-scheduled.

Parameter Type Default Description
pending PendingUploadStore
blob_storage Any
submissions Any

Method PendingUploadReaper.reap_once

Reap up to batch expired rows of tenant.

Rows are selected FOR UPDATE SKIP LOCKED and stay locked until the batch is processed, so two concurrent runs never handle the same row. Per row: a stored submission still referencing the blob drops only the row; otherwise blob (and thumbnail) are deleted strictly and the row dropped; any failure keeps the row for the next run. Never raises for a per-row problem.

reap_once(*, tenant: str, public_form_ttl: timedelta = DEFAULT_PUBLIC_FORM_TTL, ttl: timedelta = DEFAULT_TTL, batch: int = 500) -> ReapResult

Parameter Type Default Description
tenant str Tenant schema to sweep.
public_form_ttl timedelta DEFAULT_PUBLIC_FORM_TTL Age after which an upload to a public form expires.
ttl timedelta DEFAULT_TTL Age after which an upload to any other form expires.
batch int 500 Maximum number of rows handled per call.

Returns: ReapResult — Counts of deleted / failed / still-referenced rows.

Class PendingUploadStore

CRUD over <tenant>.<table> (default pending_uploads).

Parameter Type Default Description
pool Any
schema str DEFAULT_SCHEMA
table_name str DEFAULT_TABLE

Method PendingUploadStore.transaction

Yield a pooled connection inside a transaction (used by the reaper to hold row locks).

transaction() -> AsyncIterator[Any]

Returns: AsyncIterator[Any]

Method PendingUploadStore.initialize

CREATE TABLE / INDEX IF NOT EXISTS in .

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

Parameter Type Default Description
tenant str | None None

Method PendingUploadStore.record

INSERT … ON CONFLICT (blob_ref) DO UPDATE SET uploaded_at = now(), thumbnail_ref = EXCLUDED.thumbnail_ref.

record(entry: PendingUpload, *, tenant: str) -> None

Parameter Type Default Description
entry PendingUpload
tenant str

Method PendingUploadStore.clear

DELETE … WHERE blob_ref = ANY($1); uses conn when given (caller's transaction). No-op on empty.

clear(blob_refs: Iterable[str], *, tenant: str | None, conn: Any | None = None) -> int

Parameter Type Default Description
blob_refs Iterable[str]
tenant str | None
conn Any | None None

Returns: int

Method PendingUploadStore.expired

Rows past their TTL, oldest first.

(public_form AND uploaded_at < now()-public_form_ttl) OR (NOT public_form AND uploaded_at < now()-ttl). FOR UPDATE SKIP LOCKED when conn is given (caller holds a transaction).

expired(*, tenant: str, public_form_ttl: timedelta, ttl: timedelta, limit: int, conn: Any | None = None) -> list[PendingUpload]

Parameter Type Default Description
tenant str
public_form_ttl timedelta
ttl timedelta
limit int
conn Any | None None

Returns: list[PendingUpload]

Method PendingUploadStore.delete_rows

Delete rows by blob_ref (pooled connection).

delete_rows(blob_refs: Iterable[str], *, tenant: str) -> int

Parameter Type Default Description
blob_refs Iterable[str]
tenant str

Returns: int

Class ReapResult

Outcome of one reap_once run.

Fields:

Field Type Default Description
deleted int 0
failed int 0
still_referenced int 0

Function iter_blob_refs

Every str value under a blob_ref key, walking dicts/lists recursively.

Covers FileEnvelope dicts, lists of envelopes, nested groups/arrays and the legacy {answer, blob_ref, display} multi-upload item. Non-string blob_ref values are ignored.

iter_blob_refs(data: Any) -> set[str]

Parameter Type Default Description
data Any A submission data payload (any JSON-like structure).

Returns: set[str] — The set of blob refs found; empty when there are none.

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