Refactor Dataset.session_list() to match MATLAB API and improve error handling#20
Merged
Merged
Conversation
The Dataset.session_list() method was returning a tuple of (session_references, session_list) but all callers expected a flat list of dicts. This caused 20 test failures with TypeError and assertion errors about len() returning 2 (tuple size) instead of the session count. https://claude.ai/code/session_01ManyQhMJJszw7Euj7V31Z1
This reverts commit 57336c5.
session_list() returns a MATLAB-compatible tuple of (references, details) but tests were treating it as a flat list of dicts. Updated all 20 failing tests to unpack the tuple and use the details list. Also fixed Dataset.__repr__ to use the details list length. https://claude.ai/code/session_01ManyQhMJJszw7Euj7V31Z1
Match MATLAB convention where session_list() returns two cell arrays: session references and session IDs. Updated tests to unpack the tuple and use the appropriate list. Also fixed Dataset.__repr__ and the database_fun.py caller. https://claude.ai/code/session_01ManyQhMJJszw7Euj7V31Z1
- session_list() now returns 4 values (ref_list, id_list, session_doc_ids, dataset_session_doc_id) matching MATLAB signature - database_search() now searches linked sessions in addition to internal DB - add_linked_session() raises ValueError on duplicate (was silent) - add_ingested_session() checks is_fully_ingested() before ingesting - unlink_session() requires are_you_sure=True and only works on linked sessions (raises ValueError for ingested sessions) - delete_ingested_session() raises ValueError when session not found - Add _open_linked_sessions() helper for lazy session opening - Update all tests to match new 4-value return and stricter error handling https://claude.ai/code/session_01ManyQhMJJszw7Euj7V31Z1
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.
Summary
This PR refactors the
Dataset.session_list()method to return a 4-tuple matching the MATLAB API signature, and adds comprehensive error handling and validation throughout the Dataset class.Key Changes
API Changes
(list[str], list[dict])to(list[str], list[str], list[str], str)returning(refs, ids, session_doc_ids, dataset_session_doc_id)to match MATLAB behaviorremove_documents: booltoare_you_sure: boolfor consistency withdelete_ingested_session()Error Handling & Validation
add_linked_session(): Now raisesValueErrorif session already exists in dataset (previously silently returned)add_ingested_session(): Now raisesValueErrorif session already exists or is not fully ingested (previously silently returned)unlink_session(): Now requiresare_you_sure=Trueand raisesValueErrorif session not found or is ingested (previously silently returned)delete_ingested_session(): Now raisesValueErrorif session not found (previously silently returned)remove_documentsparameter fromunlink_session()- linked sessions cannot have documents removedImplementation Details
_session_cacheto track opened linked sessions for efficient access_open_linked_sessions()helper to ensure linked sessions are cacheddatabase_search()to include results from linked sessionssession_list()unpacking pattern:refs, session_ids, *_ = dataset.session_list()Test Updates
ValueErrorexceptionstest_unlink_with_remove_documents()test (feature removed)test_unlink_ingested_session()totest_unlink_ingested_session_error()to reflect new behaviortest_unlink_not_confirmed()to verify confirmation requirementhttps://claude.ai/code/session_01ManyQhMJJszw7Euj7V31Z1