fix(memory): enforce closed state on SQLite session empty add_items - #4231
Merged
seratch merged 1 commit intoAug 5, 2026
Merged
Conversation
SQLiteSession.add_items and AdvancedSQLiteSession.add_items return early on an empty list before touching a connection, so add_items([]) succeeds on a session that has already been closed. AsyncSQLiteSession, MongoDBSession, RedisSession, and DaprSession all run their closed check before the empty-list fast path. Check the closed state first in both SQLite sessions so every backend behaves the same.
seratch
approved these changes
Aug 5, 2026
seratch
enabled auto-merge (squash)
August 5, 2026 23:49
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.
SQLiteSession.add_itemsandAdvancedSQLiteSession.add_itemsreturn early on an empty list before they ever reach_get_connection, soawait session.add_items([])succeeds on a session that has already been closed while every non-empty call raisesRuntimeError("SQLiteSession is closed"). The sibling backends all order this the other way:AsyncSQLiteSession,RedisSession, andDaprSessioncall_check_not_closed()before the fast path, andMongoDBSessioncarries an explicit comment saying the check has to come first for exactly this reason.This moves the closed check ahead of the empty-list fast path in both SQLite sessions and factors the existing inline check in
_get_connectioninto a_check_not_closedhelper so there is one source of truth for the error, matching the sibling shape. Nothing else changes: a closed session already raised for every other operation, and an open session is untouched.Two regression tests, one per session class, close the session and then call
add_items([]). Both fail onmainwithFailed: DID NOT RAISE <class 'RuntimeError'>and pass with this change.make lint,make typecheck(mypy and pyright, 0 errors), and the touched test modules are green.