{"record":{"id":"12050eaef3bcf0d1","repo":"ZhuLinsen/daily_stock_analysis","slug":"intelligence-source-is-disabled-source-id","errorCode":null,"errorMessage":"Intelligence source is disabled: {source_id}","messagePattern":"Intelligence source is disabled: (.+?)","errorType":"exception","errorClass":"IntelligenceServiceError","httpStatus":400,"severity":"warning","filePath":"src/services/intelligence_service.py","lineNumber":257,"sourceCode":"            \"page_size\": max(1, min(int(filters.get(\"page_size\") or 50), 100)),\n        }\n\n    def test_source(self, payload: Dict[str, Any]) -> Dict[str, Any]:\n        fields = self._normalize_source_fields(payload)\n        entries = self._fetch_feed_entries(fields, limit=min(5, self.config.news_intel_max_items_per_source))\n        return {\n            \"ok\": True,\n            \"source\": self._redact_source_fields(fields),\n            \"fetched_count\": len(entries),\n            \"sample_items\": [self._feed_entry_to_dict(entry) for entry in entries[:5]],\n        }\n\n    def fetch_source(self, source_id: int, *, dry_run: bool = False) -> Dict[str, Any]:\n        source = self.repo.get_source(source_id)\n        if source is None:\n            raise IntelligenceServiceError(f\"Intelligence source not found: {source_id}\")\n        if not source.enabled:\n            raise IntelligenceServiceError(f\"Intelligence source is disabled: {source_id}\")\n        now = datetime.now()\n        try:\n            entries = self._fetch_feed_entries(self._source_to_fields(source), limit=self.config.news_intel_max_items_per_source)\n            item_fields = [self._entry_to_item_fields(entry, source, now) for entry in entries]\n            saved = 0 if dry_run else self.repo.upsert_items(item_fields)\n            deleted = 0 if dry_run else self.repo.apply_retention(self.config.news_intel_retention_days)\n            if not dry_run:\n                self.repo.update_source_status(source.id, status=\"success\", error=None, fetched_at=now)\n            return {\n                \"ok\": True,\n                \"source_id\": source.id,\n                \"fetched_count\": len(entries),\n                \"saved_count\": saved,\n                \"retention_deleted\": deleted,\n                \"dry_run\": dry_run,\n                \"sample_items\": [self._feed_entry_to_dict(entry) for entry in entries[:5]],\n            }\n        except Exception as exc:","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/services/intelligence_service.py#L239-L275","documentation":"fetch_source refuses to fetch a source whose enabled flag is false. The row exists but is disabled, so the service blocks the network fetch instead of silently pulling from an opted-out feed.","triggerScenarios":"Calling fetch on a source created with enabled=False (create_default_sources defaults new sources to disabled) that was never toggled on.","commonSituations":"Bulk-creating default templates (they start disabled) then immediately trying to fetch; disabling a noisy source but a scheduled job still referencing it.","solutions":["Enable the source first: update_source(source_id, {'enabled': True}) or the UI toggle, then fetch","If it should stay disabled, remove it from fetch schedules/automation","Check the 'enabled' field in list_sources output before triggering fetch"],"exampleFix":"# before\nsvc.fetch_source(sid)  # disabled -> error\n# after\nsvc.update_source(sid, {'enabled': True})\nsvc.fetch_source(sid)","handlingStrategy":"validation","validationCode":"src = svc.repo.get_source(source_id)\nif src and not src.enabled:\n    svc.update_source(source_id, {'enabled': True})\nservice.fetch_source(source_id)","typeGuard":"def is_fetchable(src) -> bool:\n    return src is not None and bool(src.enabled)","tryCatchPattern":"try:\n    svc.fetch_source(sid)\nexcept IntelligenceServiceError as e:\n    if 'disabled' in str(e):\n        svc.update_source(sid, {'enabled': True})\n        svc.fetch_source(sid)\n    else:\n        raise","preventionTips":["Note create_default_sources creates sources with enabled=False — toggle before first fetch","Show the enabled state in the UI and disable the Fetch button for disabled sources","Exclude disabled sources from scheduled fetch jobs"],"tags":["intelligence","disabled","state"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}