cache_view
Shared helpers for building a step's cache read/write view.
A cache-backed step declares the ORM model it persists to (orm_model) and,
optionally, a tuple of config-derived equality filters (cache_filter_fields).
task_hash_accessor turns that declaration into the
(cache, task_hash, config) -> CacheAccessor builder used by both the live task
(the write side) and BackgroundResultsContext (the cross-phase read side), so
the two cannot drift.
Every cache table keys on task_hash, so that filter is always applied; steps
needing only task_hash declare just orm_model, and steps needing more declare
cache_filter_fields for the additional column-equality filters.
The task_hash a step is given is its own — a Merkle hash over its semantic
config and its upstream steps' hashes (bitfount.flows.dag.hashing), not one
value shared by the whole task — so a config change lands in a fresh partition.
Nothing here needs to know that: the hash arrives as a parameter either way.
An accessor built here is therefore already scoped to the partition of the step
that produced it, which is what makes handing one down a DAG edge sufficient for
the common case. A step needing a store-level query against an upstream table
instead reads DAGStep.parent_task_hashes; it does not interrogate the accessor.
Module
Functions
project_scoped_accessor
def project_scoped_accessor( orm_model: Any, filter_fields: tuple[str, ...], cache: CacheProtocol, task_hash: str, project_id: str,) ‑> CacheAccessor:Build a step result's accessor when project_id is a runtime param.
project_id is a runtime task parameter, not a step-config field, so it is
wrapped in a small namespace that task_hash_accessor's filter reads by
attribute. Shared by scan_eligibility and patient_eligibility (both
filter on project_id) so the wrapper cannot drift between the two.
Arguments
orm_model: The SQLAlchemy mapped class the step persists to.filter_fields: The step'scache_filter_fields(its config-filter names).cache: The cache backend.task_hash: The step's partition key.project_id: The trial (project) ID runtime param.
Returns
A CacheAccessor scoped to this task_hash and project_id.
task_hash_accessor
def task_hash_accessor( orm_model: Any, *config_filter_fields: str,) ‑> collections.abc.Callable[[CacheProtocol, str, typing.Any], CacheAccessor]:Build a cache-accessor factory for a step.
The returned function filters the step's orm_model rows by task_hash
(the universal partition key shared by every cache table), plus one equality
filter per name in config_filter_fields matching a config attribute to the
same-named orm_model column.
Arguments
orm_model: The SQLAlchemy mapped class the step persists to.*config_filter_fields: Names that are both a config attribute and anorm_modelcolumn; each addsorm_model.<name> == config.<name>to the filter set.
Returns
A (cache, task_hash, config) -> CacheAccessor builder.