ZhuLinsen/daily_stock_analysis · error · IntelligenceServiceError
Intelligence source template not found: {template_id}
Error message
Intelligence source template not found: {template_id} What it means
create_source_from_template looks up template_id only in _builtin_source_templates(); unknown ids raise this IntelligenceServiceError. Templates are a fixed in-code catalog, not user data — there is no DB fetch involved.
Source
Thrown at src/services/intelligence_service.py:182
def list_source_templates(self, **filters: Any) -> Dict[str, Any]:
market = str(filters.get("market") or "").strip().lower()
source_type = str(filters.get("source_type") or "").strip().lower()
templates = []
for template in self._builtin_source_templates():
if market and template["market"] != market:
continue
if source_type and template["source_type"] != source_type:
continue
templates.append(dict(template))
return {"items": templates, "total": len(templates)}
def create_source_from_template(self, template_id: str, overrides: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
selected = next(
(dict(template) for template in self._builtin_source_templates() if template["template_id"] == template_id),
None,
)
if selected is None:
raise IntelligenceServiceError(f"Intelligence source template not found: {template_id}")
payload = {key: value for key, value in selected.items() if key != "template_id"}
payload.update({key: value for key, value in (overrides or {}).items() if value is not None})
return self.create_source(payload)
def create_default_sources(self, overrides: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
request_fields = dict(overrides or {})
request_fields.setdefault("enabled", False)
created_count = 0
items = []
for template in self._builtin_source_templates():
payload = {key: value for key, value in template.items() if key != "template_id"}
payload.update({key: value for key, value in request_fields.items() if value is not None})
existing = self.repo.get_source_by_name(str(payload["name"]))
if existing is not None:
items.append({"created": False, "source": self._source_to_dict(existing)})
continue
source = self.create_source(payload)
created_count += 1View on GitHub (pinned to 5159bd72e8)
Solutions
- Re-fetch the current template list via list_source_templates and use an id from the response
- Check spelling/case of the template_id being sent
- If a needed template vanished, create the source directly via create_source with equivalent fields
Example fix
# before
svc.create_source_from_template('cls-old-id') # removed -> error
# after
templates = svc.list_source_templates()['items']
svc.create_source_from_template(templates[0]['template_id']) Defensive patterns
Strategy: validation
Validate before calling
valid_ids = {t['template_id'] for t in svc.list_source_templates()['items']}
if template_id not in valid_ids:
refresh_template_list() # ids may have changed across versions Type guard
def is_known_template(svc, tid: str) -> bool:
return any(t['template_id'] == tid
for t in svc.list_source_templates()['items']) Try / catch
try:
svc.create_source_from_template(tid, overrides)
except IntelligenceServiceError as e:
if 'template not found' in str(e):
templates = svc.list_source_templates()['items']
tid = prompt_user_to_pick(templates)['template_id']
svc.create_source_from_template(tid, overrides)
else:
raise Prevention
- Always send template ids taken from a live list_source_templates response
- Never hardcode template ids in clients — they are a server-owned catalog
- Treat unknown-template as a refresh-and-retry UX flow, not a crash
When it happens
Trigger: Calling with a stale/typo'd template_id after built-in template ids were renamed or removed in an upgrade; client caching an old template list.
Common situations: Frontend dropdown built from an older API version; API consumer hardcoding a template id that a release removed; trailing whitespace/case mismatch in the id.
Related errors
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/0404cfc144e1f598.
Report an issue: GitHub.