Skip to content

Refactor Dataset.session_list() to match MATLAB API and improve error handling#20

Merged
stevevanhooser merged 6 commits into
mainfrom
claude/fix-python-3.12-coverage-VDIft
Mar 12, 2026
Merged

Refactor Dataset.session_list() to match MATLAB API and improve error handling#20
stevevanhooser merged 6 commits into
mainfrom
claude/fix-python-3.12-coverage-VDIft

Conversation

@stevevanhooser
Copy link
Copy Markdown
Contributor

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

  • session_list() return type: Changed from (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 behavior
  • unlink_session() signature: Changed parameter from remove_documents: bool to are_you_sure: bool for consistency with delete_ingested_session()

Error Handling & Validation

  • add_linked_session(): Now raises ValueError if session already exists in dataset (previously silently returned)
  • add_ingested_session(): Now raises ValueError if session already exists or is not fully ingested (previously silently returned)
  • unlink_session(): Now requires are_you_sure=True and raises ValueError if session not found or is ingested (previously silently returned)
  • delete_ingested_session(): Now raises ValueError if session not found (previously silently returned)
  • Removed remove_documents parameter from unlink_session() - linked sessions cannot have documents removed

Implementation Details

  • Added _session_cache to track opened linked sessions for efficient access
  • Added _open_linked_sessions() helper to ensure linked sessions are cached
  • Enhanced database_search() to include results from linked sessions
  • Updated all test files to use new session_list() unpacking pattern: refs, session_ids, *_ = dataset.session_list()
  • Improved docstrings with clearer MATLAB equivalents and error documentation

Test Updates

  • Updated 50+ test assertions to work with new 4-tuple return value
  • Changed tests expecting silent failures to expect ValueError exceptions
  • Removed test_unlink_with_remove_documents() test (feature removed)
  • Renamed test_unlink_ingested_session() to test_unlink_ingested_session_error() to reflect new behavior
  • Added test_unlink_not_confirmed() to verify confirmation requirement

https://claude.ai/code/session_01ManyQhMJJszw7Euj7V31Z1

claude added 6 commits March 11, 2026 23:37
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
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
@stevevanhooser stevevanhooser merged commit df17589 into main Mar 12, 2026
4 checks passed
@stevevanhooser stevevanhooser deleted the claude/fix-python-3.12-coverage-VDIft branch March 12, 2026 00:06
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.

2 participants