Skip to content

fix(core): restore the page cache state once per fetch_schema call - #180

Open
LukasGold wants to merge 1 commit into
mainfrom
fix/176-fetch-schema-cache
Open

LukasGold wants to merge 1 commit into
mainfrom
fix/176-fetch-schema-cache

Conversation

@LukasGold

Copy link
Copy Markdown
Contributor

Fixes #176.

Changes

  • OSW.fetch_schema reads the cache state once, enables the cache, and
    restores the state in a finally block around the loop over schema titles.
  • OSW._fetch_schema no longer reads or restores the cache state. A note in
    its docstring says where that now happens.
  • The importlib.reload(model) call under if fetchSchemaParam.final: stays
    unchanged.
  • New unit tests in tests/test_fetch_schema_cache.py.

Rationale

  • site_cache_state was a local of _fetch_schema, which runs once per title
    and again recursively per $ref. From the second title on, the snapshot
    already read the state the previous call had set, so if not site_cache_state was false and disable_cache() was never called.
  • The restore was also unreachable on two paths: the early return for a
    missing schema page, and any exception. A finally in the caller covers
    both.
  • _fetch_schema is private and only called from fetch_schema and from
    itself, so moving the cache handling to the public method keeps the caching
    benefit for the whole operation.
  • enable_cache/disable_cache are plain boolean setters with no nesting
    counter, so a single enable and a single restore around the operation is the
    correct shape.

Verification

  • 6 new tests pass.
  • 5 of the 6 fail against the previous src/osw/core.py, including the test
    for a worker that enables the cache and does not restore it.
  • The tests replace _fetch_schema with a stub, so they assert the cache
    contract of fetch_schema. They do not execute the body of _fetch_schema,
    which needs a wiki.

Related

- fetch_schema takes the cache state before the loop over schema titles
- the restore runs in a finally block, so an early return or an exception
  in _fetch_schema can no longer leave the cache enabled
- _fetch_schema no longer snapshots a state its predecessor has changed
- add unit tests for the multi-title, exception and early-return paths

Closes #176
@github-actions

Copy link
Copy Markdown
Contributor

Release preview

Merging this PR would release v2.3.4 (current: v2.3.3).

Changelog preview (truncated)
## v2.3.4 (2026-09-18)

### Bug Fixes

- **core**: Restore the page cache state once per fetch_schema call
  ([`f09dcf6`](https://github.com/OpenSemanticLab/osw-python/commit/f09dcf6b9d0e0bf3baf04107d9e1acf56e755c8d))

### Chores

- Relicense to Apache-2.0 ([#173](https://github.com/OpenSemanticLab/osw-python/pull/173),
  [`848615c`](https://github.com/OpenSemanticLab/osw-python/commit/848615cbd1e06401922eda88231a51028440a242))

Preview via python-semantic-release and conventional commits.

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.

fetch_schema leaves the page cache enabled when given more than one schema title

1 participant