Skip to content

Class-based EntityReader lookups + app-runner FindMixin migration#563

Draft
leoschwarz wants to merge 4 commits into
mainfrom
refactor/app-runner-findmixin-migration
Draft

Class-based EntityReader lookups + app-runner FindMixin migration#563
leoschwarz wants to merge 4 commits into
mainfrom
refactor/app-runner-findmixin-migration

Conversation

@leoschwarz

@leoschwarz leoschwarz commented Jul 15, 2026

Copy link
Copy Markdown
Member

FindMixin (Entity.find / find_all / find_by) is deprecated and emits DeprecationWarning on every call; bfabric_app_runner was its heaviest consumer (16 sites). This migrates them to client.reader and extracts the id-keying / not-found filtering those methods did inline into two reusable core helpers, so the migration deduplicates rather than scatters that logic.

Key changes

  • bfabric — new bfabric.entities.core.reader_utils with entities_by_id (re-key a reader result by integer id, drop not-found) and present_entities (drop not-found). FindMixin.find_all / find_by now delegate to entities_by_id.
  • bfabric_app_runner — all 16 FindMixin call sites moved to client.reader (read_id / read_ids / query_one); the four bulk read_ids sites use the new helpers.
  • Scope kept to app-runner: the core bfabric (6) and bfabric_scripts (12) FindMixin sites are separate follow-ups.

Notes for review

  • read_ids is URI-keyed and includes None for not-found (vs find_all's int-keyed, misses-dropped). The id-indexed sites re-key and drop None (so a missing id still raises KeyError downstream, as before); the value-consuming sites drop None.
  • Behavior delta: find_all logged an "Only found N out of M" warning on partial misses. That warning is no longer emitted at the two value-consuming sites (dispatch_resource_flow, resource-dataset resolve), which now drop silently; the id-keyed sites still fail loudly via KeyError.
  • Left out intentionally: dispatch_individual_resources (keeps None for a friendly per-id ValueError) and a pre-existing latent None bug in _resolve_bfabric_annotation_specs.py (a separate follow-up, not yet filed).

Testing

pytest tests/bfabric (763) and pytest tests/bfabric_app_runner (325), basedpyright (both packages, 0/0/0), and ruff — all green. New unit tests cover the helpers and the re-key / None-drop paths.

🤖 Prepared with assistance from Claude Opus 4.8 via Claude Code.

Replace all 16 deprecated Entity.find/find_all/find_by (FindMixin) read-path
call sites in bfabric_app_runner with the modern client.reader API
(read_id/read_ids/query_one). Behavior-preserving:

- find(id) -> reader.read_id(endpoint, id, expected_type=...)
- find_by(obj) -> reader.query_one(endpoint, obj, expected_type=...)
  (callers only used the first/truthiness of the result)
- find_all(ids) -> reader.read_ids(endpoint, ids, expected_type=...)
  read_ids is URI-keyed and includes None for misses, whereas find_all was
  int-keyed and dropped misses. So:
    * .values() consumers now filter out None
    * id-indexed consumers re-key uri.components.entity_id -> entity and drop
      None, preserving the prior "missing id -> KeyError" behavior

The four possibly-None accesses that were previously grandfathered in the
basedpyright baseline (execution.dataset arg, dataset.to_polars(),
registration.workunit_id/storage_id) are now handled with targeted
# pyright: ignore comments; the baseline shrinks accordingly (no new
suppressions).

Tests updated to mock the client.reader path (real EntityUri keys for
read_ids); added focused coverage for the re-key/None-drop paths in the
dataset, resource, and resource-flow resolvers.
…pers

Deduplicate the 're-key EntityReader results by id / drop not-found' transform
that FindMixin.find_all/find_by performed inline into two reusable free functions
in bfabric.entities.core.reader_utils. FindMixin now delegates to entities_by_id,
and the app-runner FindMixin-migration sites use the helpers instead of inline
dict-comprehensions, collapsing the four bulk read_ids sites to one line each.

No behavior change. The basedpyright baseline shrinks by one entry (find_by's
grandfathered reportReturnType is now fixed via a localized cast).
read_id/read_ids/query/query_one now accept an entity class in place of the
endpoint string (e.g. client.reader.read_id(Resource, id)), inferring both the
endpoint and the result type via import_entity.entity_type_of (the class->string
inverse of import_entity, keyed on the lowercase-class-name convention). The
string form (with optional expected_type) still works.

Adopt the class form across bfabric_app_runner + a few core sites, dropping the
redundant endpoint string; narrow the read-only ResolveBfabricDatasetSpecs and
ResolveBfabricResourceDatasetSpecs to take an EntityReader instead of the full
Bfabric client.
@leoschwarz leoschwarz changed the title refactor: migrate app-runner off FindMixin, extract reader helpers Class-based EntityReader lookups + app-runner FindMixin migration Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant