fix(memory): skip legacy non-string rows in AsyncSQLiteSession.get_items - #4302
Closed
hsusul wants to merge 1 commit into
Closed
fix(memory): skip legacy non-string rows in AsyncSQLiteSession.get_items#4302hsusul wants to merge 1 commit into
hsusul wants to merge 1 commit into
Conversation
Member
|
I confirmed that a manually created table with nullable However, I am going to close this PR for now. |
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
AsyncSQLiteSession.get_itemsdecodes each stored row withjson.loadsinside atry/except json.JSONDecodeError, so it only skips rows that fail to parse as JSON. Every other decode site in the session layer also skips rows whosejson.loadsraisesTypeError— i.e. rows whosemessage_datais a non-string (most commonlyNULL):AsyncSQLiteSession.pop_item—except (json.JSONDecodeError, TypeError)SQLiteSession.get_itemsand.pop_item—except (json.JSONDecodeError, TypeError)MongoDBSession.get_items—except (json.JSONDecodeError, TypeError)("Skip corrupted or malformed entries, including legacy non-string values.")Because async
get_itemswas the lone exception, a single non-string row made the entire read raiseTypeError: the JSON object must be str, bytes or bytearray, not NoneTypeinstead of skipping that row.db_path,sessions_table, andmessages_tableare public constructor arguments, so a session can be pointed at a database/table created by an older schema or external tooling whosemessage_datacolumn is nullable — exactly the "legacy non-string values" case the sibling backends already guard. This also makesget_itemsandpop_itemdisagree on the same data:pop_itemquietly drops the row whileget_itemscrashes.The fix widens the
get_itemsdecode guard to(json.JSONDecodeError, TypeError), matchingpop_itemand the other backends. Both the unlimited read and the limited (window-expanding) read share the same_decode_rowshelper, so both paths are covered.Test plan
New regression test
test_async_sqlite_session_get_items_skips_non_string_rowsseeds a legacy-shaped (nullablemessage_data) table with aNULLrow among valid rows and asserts bothget_items()andget_items(limit=1)skip it and return the valid items.main(raisesTypeError), passes with this change. Verified by reverting only thesrcchange and re-running: the read raisesTypeError.uv run pytest tests/extensions/memory/test_async_sqlite_session.py→ 40 passeduv run pytest tests/memory tests/extensions/memory/test_async_sqlite_session.py tests/extensions/memory/test_advanced_sqlite_session.py→ 232 passed, 1 skippeduv run ruff check(changed files) → All checks passeduv run ruff format --check(changed files) → already formatteduv run pyright(changed files) → 0 errors, 0 warningsgit diff --check→ cleanNot run: the full
tests/extensions/memorysuite requires optional extras (sqlalchemy, etc.) that are not installed in this minimal environment; those modules are unrelated to this change (SQLite-only fix).Issue number
N/A — no issue filed; small correctness fix consistent with the sibling backends.
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR