fix(core): report dropped entities and restore the cache on error - #185
Merged
Merged
Conversation
- store_entity_ raises instead of returning when it cannot determine the title or the namespace, so the collector loop records the entity - both cases now appear in StoreEntityResult.failed instead of nowhere - load_entity restores the page cache state in a finally block - adds offline regression tests for both paths Closes #183
Contributor
Release previewNo version bump from the current commits (stays at Changelog preview (truncated)Preview via python-semantic-release and conventional commits. |
- the fake page raises from get_slot_content, after get_page succeeded - shows the finally block covers the whole body, not only its first call - both new cases fail when the try/finally is removed
- StoreEntityResult.failed falls back to the entity name, uuid or 'unknown' when the title or the namespace cannot be resolved - those fallback forms became reachable with the two new raises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #183. Two independent gaps in
src/osw/core.py.Based on
fix/175-store-entity-verify(#182), not on main, because the first change touchesstore_entity_, the same function #182 changes, and the new tests depend on the write verification it adds. GitHub retargets this PR to main once #182 merges.1.
store_entity_no longer drops an entity silentlyTwo error paths logged and returned. A plain
returnis not an exception, sohandle_upload_object_returned normally, the collector loop atsrc/osw/core.py:2048-2052recorded nothing, and the entity reached neitherStoreEntityResult.pagesnorStoreEntityResult.failed.store_entitythen returned without raisingStoreEntityPartialError, so the caller saw a successful call with fewer pages than entities passed in.Both conditions now raise, so the existing collector loop records them:
get_title(entity_)raises:ValueError, chained from the original exceptionnamespace_ortitle_isNone:TypeError, matching the neighbouringraise TypeErrorfor a missingoverwrite_class_paramThe local
_logger.errorcall in the first branch was removed, because the collector loop already logs every failed entity.Behaviour change
An entity that met one of these two conditions previously caused no exception. It now contributes to
StoreEntityResult.failed, which makesstore_entityraiseStoreEntityPartialError. A caller that depended on the silent drop will now see the error.2.
load_entityrestores the page cache state in afinallyblockThe state was saved at the start and restored near the end, outside any
try. An exception from the calls in between (get_page,get_slot_content, the category schema fetch,fetch_schema,namespace_from_full_title) left the cache in the state set for the load. That is the failure mode of #176: a laterget_pagecan return a revision from before a write.The body is now wrapped in
tryand the restore is infinally. Only indentation changed inside the body.ruff formatrewrapped two lines that the extra indentation pushed past the line limit._fetch_schemahad the same pattern and is fixed separately in #180.Tests
tests/test_store_entity_silent_drop.py, 6 tests: title failure reported in both the serial and the parallel path, missing namespace, missing title, a mixed batch where only the failing entity is reported, and a normal-path guard.tests/test_load_entity_cache_restore.py, 8 tests: the cache state survives an exception fromget_pagefor both starting states, the same for an exception raised inside the per-page loop afterget_pagesucceeded, plus normal-path guards.Both files run offline. Reverting only the
try/finallyand rerunningtests/test_load_entity_cache_restore.pygives 4 failed, 4 passed. The four that fail are the twoget_pagecases withdisable_cache=Trueand both page-loop cases. The other four cannot discriminate, because withdisable_cache=Falsethe cache is never changed at all.The page-loop test exists because a test that only raises from
get_pagewould still pass if thetrycovered just the first statement of the body.Full unit suite: 231 passed.
Not addressed
load_entityhas a separate pre-existing defect atsrc/osw/core.py:1222-1228:disable_cache=Truesets the cache to the opposite of the caller's starting state instead of disabling it. Filed as #186. This PR keeps that behaviour unchanged.