Skip to content

Commit 7607e14

Browse files
hobostayclaudeWillemJiang
authored
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 <noreply@anthropic.com> Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
1 parent fb2f54c commit 7607e14

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/graph/checkpoint.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ def __init__(
5353
self.postgres_conn = None
5454

5555
if self.checkpoint_saver:
56-
if self.db_uri.startswith("mongodb://"):
56+
if self.db_uri is None:
57+
self.logger.warning(
58+
"Checkpoint saver is enabled but db_uri is None. "
59+
"Please provide a valid database URI or disable checkpoint saver."
60+
)
61+
elif self.db_uri.startswith("mongodb://"):
5762
self._init_mongodb()
5863
elif self.db_uri.startswith("postgresql://") or self.db_uri.startswith(
5964
"postgres://"

0 commit comments

Comments
 (0)