Skip to content

tdfs4ds.finding_acceptance

tdfs4ds.finding_acceptance

Accepted findings: FS_FINDING_ACCEPTANCE (0.3.7.34).

Some findings of the workflow assessment / sanity check are correct but expected (base tables behind an access layer of views, an empty first month because the source starts later). An administrator accepts one with a justification; the report then leaves it out of the error and warning counts and the verdict and lists it under Accepted, with who accepted it, when, why and until when. Nothing disappears silently.

Identity. :func:finding_identity is the ONE definition of "the same finding": the check (kind), the object, the business dates it concerns and a hash of its detail with the volatile parts removed (numbers, dates). An acceptance covers exactly that identity: another object, other dates or a changed detail is a new finding, and so is the same finding after the acceptance expired. :func:match_acceptances is pure.

Storage. An optional valid-time table in the store (the team sees the same acceptances), created at setup() / connect() or by the first acceptance; a failed CREATE is remembered and warned once. Every INSERT names its columns. Everything reading it is fail-open: no table, or an unreadable one, means nothing is accepted and the assessment is what it always was.

_STATE module-attribute

_STATE: dict = {}

_WARNED module-attribute

_WARNED: set = set()

EXPIRING_SOON_DAYS module-attribute

EXPIRING_SOON_DAYS = 14

_ISO_DATE module-attribute

_ISO_DATE = re.compile('\\d{4}-\\d{2}-\\d{2}')

_NUMBER module-attribute

_NUMBER = re.compile('\\d+(?:[.,:]\\d+)*')

_SEV_RANK module-attribute

_SEV_RANK = {'error': 0, 'warning': 1, 'info': 2}

_FIELDS module-attribute

_FIELDS = ('key', 'check', 'area', 'object', 'dates', 'detail_hash', 'detail', 'justification', 'accepted_by', 'editor', 'accepted_at', 'expires_at')

logger_safe

logger_safe(level, message, *args, **kwargs)

Wrapper around the global logger that only emits logs when tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.

sql_literal

sql_literal(value)

Escape value for use inside a single-quoted SQL string literal.

For the DBC probes and catalog predicates that compare a name as data (WHERE DatabaseName = '…'). The caller supplies the surrounding quotes.

_norm_object

_norm_object(obj) -> str

_norm_kind

_norm_kind(kind) -> str

finding_dates

finding_dates(finding: dict) -> List[str]

The sorted business dates a finding concerns: its dates field plus every ISO date its detail names (a finding that carries its date only in the text is re-opened by another date too).

normalise_detail

normalise_detail(detail) -> str

The detail without what changes from run to run: dates, numbers, case, spacing.

detail_hash

detail_hash(detail) -> str

identity_key

identity_key(check, obj, dates, detail_hash_value) -> str

finding_identity

finding_identity(finding: dict) -> dict

{"check", "object", "dates", "detail_hash", "key"} of a finding dict (as built by the assessment): the identity an acceptance is matched on.

_to_dt

_to_dt(value) -> Optional[datetime.datetime]

_now

_now(now=None) -> datetime.datetime

is_expired

is_expired(acceptance: dict, now=None) -> bool

expires_soon

expires_soon(acceptance: dict, now=None, days: int = EXPIRING_SOON_DAYS) -> bool

_covers

_covers(acc: dict, ident: dict) -> bool

severity_note

severity_note(acceptance: dict, current: str) -> Optional[str]

Why an accepted finding's acceptance may no longer be needed, or None (0.3.8.1). Pure.

The severity at acceptance is recorded since 0.3.8.1 (in the AREA column, after a |, no new column); an earlier acceptance has none. Recorded and different: "accepted when it was X". Not recorded and the finding is now info: info findings are in no count, so accepting one changes nothing. Equal severities: no note.

match_acceptances

match_acceptances(findings, acceptances, now=None) -> Tuple[List[dict], List[dict], List[dict]]

(open, accepted, expired) for findings and the acceptances read from the store.

  • accepted: the finding, with an acceptance dict (justification, accepted_by, accepted_at, expires_at, expires_soon): an acceptance still in force whose identity equals the finding's.
  • open: every other finding. One that an acceptance of the same check and object no longer covers carries reopened: 'expired' (the acceptance ended) or 'changed' (other dates or another detail than what was accepted).
  • expired: the acceptances past their expiry date (listed, never dropped).

Pure. No acceptance gives (findings, [], []) with the findings untouched.

_table_name

_table_name() -> str

_view_name

_view_name() -> str

_qualified_table

_qualified_table() -> str

_key

_key() -> Optional[str]

reset_state

reset_state() -> None

_warn_once

_warn_once(key: str, message: str, *args) -> None

_execute

_execute(sql: str)

acceptance_ddl

acceptance_ddl() -> str

acceptance_view_sql

acceptance_view_sql() -> str

_view_missing

_view_missing(existing: Optional[Iterable[str]] = None) -> bool

Whether the public view is absent. existing (connect's DBC read of the table database) answers when views live in the table database; otherwise one DBC read. A failed read counts as absent: the REPLACE VIEW that follows is harmless when the view exists (0.3.7.34 field report: a store whose first connect failed on the view never got it, since the table existed).

_create_view

_create_view(label: str) -> None

Create the public view of an existing table; a refusal is a warning (a read-only user).

acceptance_creation

acceptance_creation(existing: Optional[Iterable[str]] = None) -> bool

Create the table and its view when missing. Never raises; returns whether it is usable.

available

available() -> bool

Whether the table exists in the primary store (checked once per store).

_lit

_lit(v) -> str

_expiry_literal

_expiry_literal(until) -> str

TIMESTAMP '...' for a date / timestamp / ISO text (no zone = UTC); NULL for none.

accept_sql

accept_sql(ident: dict, *, area, detail, justification, until, editor) -> str

The statement recording one acceptance: a valid-time MERGE on the key, every column named.

revoke_sql

revoke_sql(key: str) -> str

list_sql

list_sql() -> str

_row_to_dict

_row_to_dict(row) -> dict

read_acceptances

read_acceptances() -> List[dict]

Every acceptance of the store (expired ones included), [] when there is no table or it cannot be read. Fail-open: the assessment is then what it always was.

_identity_from_args

_identity_from_args(check, object, business_dates, finding) -> Tuple[dict, str, str]

accept_finding

accept_finding(check: Optional[str] = None, object: Optional[str] = None, *, justification: str, until=None, business_dates=None, finding: Optional[dict] = None, editor: Optional[str] = None, dry_run: bool = False) -> dict

Accept a finding of the workflow assessment, with a justification.

Parameters

check, object : str The finding's kind (e.g. 'completed_on_empty_upstream') and object. Given alone, the acceptance covers that check and object whatever the detail says; business_dates narrows it to the dates named (a finding with other dates is a new one). finding : dict, optional A finding of assess_workflow()['findings']: its check, object, dates AND detail define what is accepted (the finding re-opens when any of them changes). The easy way. justification : str Required and non-empty: why this finding is expected. until : date, datetime or str, optional Expiry; the finding re-opens after it. No zone = UTC. editor : str, optional Who is accepting, as declared (the database user is recorded too). dry_run : bool Return the statement, write nothing.

Returns {"key", "check", "object", "dates", "sql", "written"}. Raises ValueError for an empty justification and RuntimeError when the table cannot be created. For administrators: the admin app restricts the action to its admin profile, and the database rights on the table apply.

list_accepted_findings

list_accepted_findings(include_expired: bool = False, now=None)

The acceptances of the store as a DataFrame (newest first): key, check, area, object, dates, justification, accepted_by, editor, accepted_at, expires_at, state (active / expires soon / expired). Expired ones only with include_expired=True. Empty when there is no table.

revoke_finding

revoke_finding(key=None, object: Optional[str] = None, business_dates=None, *, dry_run: bool = False) -> dict

Revoke an acceptance: by its key (from :func:list_accepted_findings), by a finding dict, or by (check, object, business_dates), key then holding the check. The finding is open again at the next assessment; the history stays in the table (NONSEQUENCED VALIDTIME).

acceptances_for_migration

acceptances_for_migration(plan_objects: Iterable[str], acceptances: Optional[list] = None) -> List[dict]

The acceptances of the (source) store that concern one of plan_objects (names, with or without database / quotes): for the migration plan to list, never to copy. The match is on the object's bare name appearing among the words of the acceptance's object text.