cadrumo.adapters.persistence.profile.filing_drafts module

Governed-persistence repository for filing drafts.

ModeloDraft records carry exact casilla arithmetic and tax due values. They are stored as encrypted byte objects via SecureObjectRepository at FINANCIAL SensitivityClass and serialised through an Envelope by SecureBoundRepository; no plaintext draft JSON or envelope file lands on disk.

This concrete repository lives in the persistence adapter (not in domain.filing) because its SecureBoundRepository base is SQL/crypto-coupled; the domain package owns the typed ModeloDraft payload.

See also

ModeloDraft

Strict filing payload persisted by this repository.

SecureBoundRepository

Generic encrypted-envelope repository base used for the draft store.

adapters.persistence.storage.secure_object_namespaces.FILING_DRAFTS_NAMESPACE

Namespace, sensitivity, schema-version, object-key, and custody contract for draft secure objects.

application.filing

Application review flow that reads and updates persisted drafts.

class ModeloDraftRepository(*, bucket_id=None, objects=None)[source]

Bases: SecureBoundRepository[ModeloDraft]

Encrypted FINANCIAL repository for ModeloDraft payloads.

The SecureBoundRepository base wraps each draft in an Envelope and writes it under adapters.persistence.storage.secure_object_namespaces.FILING_DRAFTS_NAMESPACE. The draft id is the natural key, so list and iteration APIs expose draft aggregates rather than submission or amendment records. The namespace definition supplies the FINANCIAL SensitivityClass, schema version, object-key grammar, and custody contract.

Parameters:
namespace: ClassVar[str]
sensitivity: ClassVar[SensitivityClass]
schema_version: ClassVar[int]
classmethod payload_model()[source]

Return the ModeloDraft encrypted payload model for filing drafts.

Return type:

type[ModeloDraft]

property bucket_id: str | None

Return the profile bucket id when this repository resolved one.

extract_identifier(payload)[source]

Return the natural id for payload (used as the SQL object key).

Subclasses MUST override. The base implementation raises NotImplementedError.

Return type:

str

Parameters:

payload (ModeloDraft)

save(payload)[source]

Persist payload after confirming draft_id is its content address.

draft_id is documented as a hash over the draft’s modelo, period, taxpayer, registry snapshot, casilla values, and binding values, and compute_modelo_draft_id() is its sole canonical derivation — but nothing recomputed it, so an arbitrary, blank, whitespace, or stale id was persisted and reloaded unchanged and a stored draft could claim an identity that was not its own content. Two different drafts could then occupy one row, or one draft two rows.

The check lives here rather than on the model because the id is a durable claim: an in-memory draft may legitimately carry a caller-chosen handle while its content is still being assembled, but once written it is the natural key this repository files it under and every later reader resolves it by.

Parameters:

payload (ModeloDraft) – The ModeloDraft aggregate to persist under its own content-addressed draft_id.

Raises:

FilingValidationError – draft_id is not the content address the canonical helper derives for this draft.

Return type:

None

to_secure_object_write(payload, *, expected_revision_id=None)[source]

Prepare the same identity-preserving encrypted payload as save().

Core types: ModeloDraft.

Return type:

SecureObjectWrite

Parameters:
iter_drafts()[source]

Yield every persisted ModeloDraft, in lexicographic id order.

Return type:

Iterator[ModeloDraft]