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>
This commit is contained in:
hobostay
2026-02-09 21:44:01 +08:00
committed by GitHub
parent fb2f54c4ac
commit 7607e14088

View File

@@ -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://"