From 7607e140884554f8dc3a3000035403f638033edd Mon Sep 17 00:00:00 2001 From: hobostay <110803307+hobostay@users.noreply.github.com> Date: Mon, 9 Feb 2026 21:44:01 +0800 Subject: [PATCH] fix: Add None check for db_uri in ChatStreamManager (#854) This commit fixes a potential AttributeError in ChatStreamManager.__init__(). Problem: - When checkpoint_saver=True and db_uri=None, the code attempts to call self.db_uri.startswith() on line 56, which raises AttributeError - Line 56: if self.db_uri.startswith("mongodb://"): This fails with "AttributeError: 'NoneType' object has no attribute 'startswith'" Root Cause: - The __init__ method accepts db_uri: Optional[str] = None - If None is passed, self.db_uri is set to None - The code doesn't check if db_uri is None before calling .startswith() Solution: - Add explicit None check before string prefix checks - Provide clear warning message when db_uri is None but checkpoint_saver is enabled - This prevents AttributeError and helps users understand the configuration issue Changes: ```python # Before: if self.checkpoint_saver: if self.db_uri.startswith("mongodb://"): # After: if self.checkpoint_saver: if self.db_uri is None: self.logger.warning( "Checkpoint saver is enabled but db_uri is None. " "Please provide a valid database URI or disable checkpoint saver." ) elif self.db_uri.startswith("mongodb://"): ``` This makes the error handling more robust and provides better user feedback. Co-authored-by: Claude Sonnet 4.5 Co-authored-by: Willem Jiang --- src/graph/checkpoint.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/graph/checkpoint.py b/src/graph/checkpoint.py index 0ed9c37..33e8b4b 100644 --- a/src/graph/checkpoint.py +++ b/src/graph/checkpoint.py @@ -53,7 +53,12 @@ class ChatStreamManager: self.postgres_conn = None if self.checkpoint_saver: - if self.db_uri.startswith("mongodb://"): + if self.db_uri is None: + self.logger.warning( + "Checkpoint saver is enabled but db_uri is None. " + "Please provide a valid database URI or disable checkpoint saver." + ) + elif self.db_uri.startswith("mongodb://"): self._init_mongodb() elif self.db_uri.startswith("postgresql://") or self.db_uri.startswith( "postgres://"