Repository navigation
open_doc: don't ask a two-argument handler for a series member (port handlerTakesContext) - #92
Merged
Conversation
Port of DID-matlab's handlerTakesContext gate (3299ab8, #188). A series member has no location of its own, so the handler is given the series manifest's location and the member's uid in the context. A handler that takes only (dest_path, source_path) never sees that uid and cannot know which member is wanted. Whatever it writes would be cached under the member's uid as the wrong bytes. MATLAB's fetchSeriesMemberBytes does not call such a handler. Python did, and only caught the case where the bytes happened to equal the manifest's. _handler_takes_context is factored out of _dispatch_custom_file_handler, mirroring MATLAB's handlerTakesContext. _open_series_member now raises DID:SQLITEDB:FileSeries:MemberNotHere for a two-argument handler, as it does with no handler, without calling it. This changes behaviour for callers: a two-argument handler that used to serve series members now gets MemberNotHere. The test that asserted the old behaviour is flipped. The add path is unchanged: two-argument handlers still ingest, as in MATLAB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Dn4gCNCU2jUGdmfPVCAGK
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.
Closes the divergence recorded on the
handlerTakesContextbridge entry in #91.The divergence
A file-series member has no location of its own. To fetch one, the
customFileHandleris given the series manifest's location, and the member's uid travels in the third (context) argument. A handler that takes only(dest_path, source_path)never sees that uid, so it cannot know which member is wanted. Whatever it writes gets cached under the member's uid as the wrong bytes.fetchSeriesMemberBytes, 3299ab8, #188) checkshandlerTakesContextand doesn't call such a handler. The member counts as not on this machine._open_series_member) called any handler. Afterwards it only caught the case where the handler returned the manifest's own bytes. A two-argument handler that returned anything else was accepted and cached.The change
_handler_takes_context(handler)out of_dispatch_custom_file_handler. It mirrors MATLAB'shandlerTakesContext: three or more positional parameters, or*args, means the handler takes the context. A callable that can't be inspected answersFalse, MATLAB's safe default. Dispatch now uses the same function, so the gate and the call can't disagree._open_series_memberraisesDID:SQLITEDB:FileSeries:MemberNotHerefor a two-argument handler, as it does with no handler, without calling it. The message tells the caller to accept a third,contextargument.handlerTakesContextnow maps to_handler_takes_contextand records the port.Behaviour change for callers
A two-argument handler that used to serve series members now gets
MemberNotHerewhen opening a member that isn't local. That matches MATLAB, and those members were being served from a request that never said which member was wanted. The add path is unchanged: two-argument handlers still ingest, as in MATLAB. So does the manifest fetch, which passes the manifest's own uid and location.test_a_two_argument_handler_is_still_calledasserted the old behaviour, so it is flipped totest_a_two_argument_handler_is_not_asked_for_a_member.Tests
tests/test_open_doc_file_series.py:*argshandler is still asked, with the context;TestHandlerTakesContextcovers 2 vs. 3 positional parameters,*args, keyword-only parameters not counting, bound methods (withselfexcluded), and an uninspectable callable.*argstest passes either way, as it should.black --check,ruff check(0.16.5),pytest(781 passed), andcheck_bridge_coverage.py(0 problems).Not changed
In
_dispatch_custom_file_handler, an uninspectable callable is still tried with three arguments and then two onTypeError, rather than given the two-argument contract outright. That only affects the dispatch. The gate follows MATLAB, and the remaining difference is recorded in the bridge entry.🤖 Generated with Claude Code
https://claude.ai/code/session_012Dn4gCNCU2jUGdmfPVCAGK