app.domain.relationships¶
Relationship resolution across a set of record summaries.
Outbound links are authored by UUID. A link from record S to UUID U resolves to the record with that UUID, preferring, in order:
the same project of the same registration (
same_project),the same registration (
same_registration),any registration (
global).
Rows of one logical identity (the published row and its candidates on
other refs) are revisions of one decision, not separate targets: each
identity is represented by its published row, else by its most
recently updated candidate. If several identities (or several published
rows of one identity) share the best tier the link is ambiguous: it
is left unresolved and reported (ambiguous_target); nothing is
picked arbitrarily. An unknown UUID yields missing_target. A record
never resolves a link to itself or to another revision of itself.
From the resolved links the index derives, for one record:
inbound links:
updated_by/obsoleted_by;errata: erratum records whose
correctslink (authored aserratum-for) resolves to the record. The erratum’s own outboundcorrectslink resolves like any other link;display status:
obsoletedif anything obsoletes it, elseupdatedif anything updates it, elseactive;duplicate_uuidissues: an error when another published file of the same identity (same registration, project and UUID) uses the UUID (only for a published record), a warning when other identities use it. Candidates of the record’s own identity are revisions and are never reported.
Records without a valid UUID take no part in UUID relationships.
Callers pass one summary per stored row: normally the published rows
plus, optionally, candidate rows (published=False).
Public API: DisplayStatus, InboundType,
Resolution, RecordSummary, ResolvedLink,
InboundLink, RelationshipView,
RelationshipIndex, resolve_relationships().
- class app.domain.relationships.DisplayStatus(*values)¶
Bases:
StrEnumDisplay status derived from inbound lifecycle links.
- ACTIVE = 'active'¶
- UPDATED = 'updated'¶
- OBSOLETED = 'obsoleted'¶
- class app.domain.relationships.InboundType(*values)¶
Bases:
StrEnumReverse names of the
updates/obsoleteslinks.- UPDATED_BY = 'updated_by'¶
- OBSOLETED_BY = 'obsoleted_by'¶
- class app.domain.relationships.Resolution(*values)¶
Bases:
StrEnumTier at which an outbound link was resolved.
- SAME_PROJECT = 'same_project'¶
- SAME_REGISTRATION = 'same_registration'¶
- GLOBAL = 'global'¶
- class app.domain.relationships.RecordSummary(key, identity, adr_uuid, links=Links(updates=(), obsoletes=(), corrects=None), record_kind=RecordKind.DECISION, path='', published=True, updated_at=None)¶
Bases:
objectThe relationship-relevant facts about one stored record row.
- Parameters:
key (
str) – Caller-chosen unique row key (e.g. the record id).identity (
Identity) – Logical identity of the record.adr_uuid (
UUID|None) – Authored UUID,Noneif missing or invalid.links (
Links) – Validated outbound links.record_kind (
RecordKind) – Decision or erratum.path (
str) – File path, used only in messages.published (
bool) –Truefor a published row,Falsefor a candidate (a revision on another ref).updated_at (
datetime|None) – When the row’s content last changed; picks the representative candidate of an unpublished identity.
- record_kind: RecordKind¶
- class app.domain.relationships.ResolvedLink(link_type, target_uuid, target_key, resolution, candidates=())¶
Bases:
objectOne outbound link and how it resolved.
- Parameters:
link_type (
LinkType) – The authored relationship.target_uuid (
UUID) – The authored target UUID.target_key (
str|None) – Row key of the resolved target, orNone.resolution (
Resolution|None) – Tier used, orNonewhen unresolved.candidates (
tuple[str,...]) – Row keys of equally good targets when ambiguous.
- resolution: Resolution | None¶
- class app.domain.relationships.InboundLink(link_type, source_key)¶
Bases:
objectA link from another record to this one.
- Parameters:
link_type (
InboundType) –updated_byorobsoleted_by.source_key (
str) – Row key of the linking record.
- link_type: InboundType¶
- class app.domain.relationships.RelationshipView(key, outbound, inbound, errata, status, issues)¶
Bases:
objectAll relationship facts for one record.
- Parameters:
key (
str) – Row key of the record.outbound (
tuple[ResolvedLink,...]) – Resolved outbound links in authored order.inbound (
tuple[InboundLink,...]) – Inboundupdated_by/obsoleted_bylinks.errata (
tuple[str,...]) – Row keys of errata correcting this record.status (
DisplayStatus) – Derived display status.issues (
tuple[Issue,...]) –missing_target,ambiguous_targetandduplicate_uuidissues for this record.
- outbound: tuple[ResolvedLink, ...]¶
- inbound: tuple[InboundLink, ...]¶
- status: DisplayStatus¶
- inbound_keys(link_type)¶
List the row keys of inbound links of one type.
- Parameters:
link_type (
InboundType) – The inbound type to select.- Return type:
- Returns:
Source row keys, e.g. the records obsoleting this one.
- class app.domain.relationships.RelationshipIndex(summaries)¶
Bases:
objectPre-computed relationships for a set of record summaries.
Build it once per set of summaries, then call
view()per record. The index is not modified after construction.
- app.domain.relationships.resolve_relationships(summaries, key)¶
Compute the relationship view of one record in a single call.
Use
RelationshipIndexdirectly when viewing many records.- Parameters:
summaries (
Iterable[RecordSummary]) – All summaries to resolve against.key (
str) – Row key of the record of interest.
- Return type:
- Returns:
The relationship view.
- Raises:
KeyError – If key is not among summaries.