fix(group_chat_context): use .get() to avoid KeyError when config profile lacks image_caption_prompt#9216
fix(group_chat_context): use .get() to avoid KeyError when config profile lacks image_caption_prompt#9216tsaitang404 wants to merge 0 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies group_chat_context.py to safely retrieve image_caption_prompt from the configuration using .get() with a default value. The reviewer identified a potential AttributeError if provider_settings is explicitly set to None and provided a safer alternative using (cfg.get("provider_settings") or {}) to handle this case.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| cfg = self.context.get_config(umo=event.unified_msg_origin) | ||
| group_context_cfg = cfg["provider_ltm_settings"] | ||
| image_caption_prompt = cfg["provider_settings"]["image_caption_prompt"] | ||
| image_caption_prompt = cfg.get("provider_settings", {}).get("image_caption_prompt", "Please describe the image using Chinese.") |
There was a problem hiding this comment.
If provider_settings is explicitly configured as null (or parsed as None), cfg.get("provider_settings", {}) will return None instead of {}. Calling .get() on None will then raise an AttributeError. Using (cfg.get("provider_settings") or {}) is safer and prevents potential runtime crashes.
| image_caption_prompt = cfg.get("provider_settings", {}).get("image_caption_prompt", "Please describe the image using Chinese.") | |
| image_caption_prompt = (cfg.get("provider_settings") or {}).get("image_caption_prompt", "Please describe the image using Chinese.") |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- You still access
cfg["provider_ltm_settings"]with direct indexing; if older configs can also miss this key, consider using.get()or validating the structure before use to avoid similarKeyErrors. - The hard-coded fallback prompt "Please describe the image using Chinese." may not be appropriate for all deployments; consider pulling this default from a shared constant or configuration so language and phrasing can be adjusted centrally.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You still access `cfg["provider_ltm_settings"]` with direct indexing; if older configs can also miss this key, consider using `.get()` or validating the structure before use to avoid similar `KeyError`s.
- The hard-coded fallback prompt "Please describe the image using Chinese." may not be appropriate for all deployments; consider pulling this default from a shared constant or configuration so language and phrasing can be adjusted centrally.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
astrbot-docs | d0e5e68 | Jul 12 2026, 08:24 AM |
Description
When
group_chat_context.pyaccesses the config viacfg["provider_settings"]["image_caption_prompt"], it raisesKeyErrorif the config profile was created before this field was added.Root Cause
group_chat_context.py:59uses direct dict indexing:cfgcomes fromget_config(umo=...)which may return an older profile without this key.Fix
Use
.get()with default fallback:Summary by Sourcery
Bug Fixes: