ZhuLinsen/daily_stock_analysis · error · IntelligenceServiceError
source name is required
Error message
source name is required
What it means
Validation in _normalize_source_fields: the name field, after str()/strip(), is empty. Every source-creating/updating path (create_source, create_source_from_template, create_default_sources, test_source) funnels through this normalizer, so a blank name fails everywhere consistently.
Source
Thrown at src/services/intelligence_service.py:370
finally:
with cls._auto_fetch_condition:
cls._auto_fetch_last_run_at = datetime.now()
cls._auto_fetch_last_result = dict(result)
cls._auto_fetch_in_progress = False
cls._auto_fetch_condition.notify_all()
return result
def _normalize_source_fields(self, payload: Dict[str, Any]) -> Dict[str, Any]:
name = str(payload.get("name") or "").strip()
url = str(payload.get("url") or "").strip()
source_type = str(payload.get("source_type") or "rss").strip().lower()
scope_type = str(payload.get("scope_type") or "market").strip().lower()
scope_value = str(payload.get("scope_value") or "").strip() or None
market = str(payload.get("market") or "cn").strip().lower()
enabled = bool(payload.get("enabled", True))
description = str(payload.get("description") or "").strip() or None
if not name:
raise IntelligenceServiceError("source name is required")
if not url:
raise IntelligenceServiceError("source url is required")
if source_type not in _ALLOWED_SOURCE_TYPES:
raise IntelligenceServiceError(f"unsupported source_type: {source_type}")
if scope_type not in _ALLOWED_SCOPE_TYPES:
raise IntelligenceServiceError(f"unsupported scope_type: {scope_type}")
if scope_type in {"symbol", "sector"} and not scope_value:
raise IntelligenceServiceError(f"scope_value is required when scope_type={scope_type}")
if market not in _ALLOWED_MARKETS:
raise IntelligenceServiceError(f"unsupported market: {market}")
return {
"name": name[:100],
"source_type": source_type,
"url": url,
"enabled": enabled,
"scope_type": scope_type,
"scope_value": scope_value[:64] if scope_value else None,
"market": market,View on GitHub (pinned to 5159bd72e8)
Solutions
- Provide a non-empty name (max 100 chars after strip)
- Add required-field validation in the client form before submit
- If overriding from a template, don't include a name key to keep the template's name
Example fix
# before
svc.create_source({'name': ' ', 'url': 'https://...'}) # -> error
# after
svc.create_source({'name': '财联社快讯', 'url': 'https://...'}) Defensive patterns
Strategy: validation
Validate before calling
name = str(payload.get('name') or '').strip()
if not name:
raise UserError('名称不能为空') Type guard
def has_source_name(payload: dict) -> bool:
return bool(str(payload.get('name') or '').strip()) Try / catch
try:
svc.create_source(payload)
except IntelligenceServiceError as e:
if 'name is required' in str(e):
focus_field('name')
else:
raise Prevention
- Mark name required in the create-source form
- Strip whitespace client-side before submit
- When overriding templates, omit the name key to inherit the template's name
When it happens
Trigger: POSTing a source with name omitted, empty string, or whitespace-only; overrides payload passing name=None.
Common situations: Form submitted without the required field; API client sending {'name': ''}; template override accidentally blanking the name.
Related errors
- source url is required
- stock_code is required
- trigger_source is required
- {field_name} is required
- unsupported source_type: {source_type}
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/88bc9f9a2a91c452.
Report an issue: GitHub.