{"record":{"id":"03eb9f1f6395ee4d","repo":"ZhuLinsen/daily_stock_analysis","slug":"source-report-not-found","errorCode":"source_report_not_found","errorMessage":"source report not found: {source_report_id}","messagePattern":"source report not found: (.+?)","errorType":"http","errorClass":"DecisionSignalSourceReportNotFoundError","httpStatus":404,"severity":"error","filePath":"src/services/decision_signal_reassess_service.py","lineNumber":72,"sourceCode":"        signal_service: Optional[DecisionSignalService] = None,\n    ) -> None:\n        self.db = db or DatabaseManager.get_instance()\n        self.signal_service = signal_service or DecisionSignalService(db_manager=self.db)\n\n    def reassess(\n        self,\n        *,\n        source_report_id: int,\n        decision_profile: str,\n        persist: bool = False,\n    ) -> dict[str, Any]:\n        decision_profile_norm = normalize_decision_profile(decision_profile)\n        if decision_profile_norm is None:\n            raise ValueError(\"decision_profile is required\")\n\n        record = self.db.get_analysis_history_by_id(source_report_id)\n        if record is None:\n            raise DecisionSignalSourceReportNotFoundError(f\"source report not found: {source_report_id}\")\n\n        raw_result = _parse_mapping(getattr(record, \"raw_result\", None))\n        context_snapshot = _parse_mapping(getattr(record, \"context_snapshot\", None))\n        candidate = _build_candidate(record, raw_result, context_snapshot)\n        data_quality_level = normalize_decision_signal_data_quality(\n            _first_present(\n                _nested_get(context_snapshot, (\"analysis_context_pack_overview\", \"data_quality\")),\n                _nested_get(context_snapshot, (\"data_quality\",)),\n                _nested_get(raw_result, (\"analysis_context_pack_overview\", \"data_quality\")),\n                _nested_get(raw_result, (\"data_quality\",)),\n            )\n        )\n        policy = apply_decision_profile_policy(\n            candidate,\n            decision_profile=decision_profile_norm,\n            data_quality_level=data_quality_level,\n        )\n        preview_candidate = policy.candidate","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/services/decision_signal_reassess_service.py#L54-L90","documentation":"The reassess flow loads a source analysis report by id via db.get_analysis_history_by_id; a missing record raises DecisionSignalSourceReportNotFoundError (code=source_report_not_found), which the API maps to an HTTP error on the reassess endpoint.","triggerScenarios":"POST /api/v1/decision-signals/reassess (preview or persist) with source_report_id that has no row in analysis_history — deleted history, wrong environment DB, or a plain typo in the id.","commonSituations":"Reassessing old reports after history retention pruned them; ids from a different instance; UI deep links to purged reports.","solutions":["Confirm the report exists: GET the analysis-history detail endpoint for that id first.","Use an id from the history list response of the same environment.","If history was pruned, pick a still-retained report to reassess."],"exampleFix":"# before\nresult = service.reassess(source_report_id=12345, decision_profile=\"balanced\")\n\n# after\nrecord = db.get_analysis_history_by_id(12345)\nif record is None:\n    raise SystemExit(\"pick a valid report id from the history list\")\nresult = service.reassess(source_report_id=12345, decision_profile=\"balanced\")","handlingStrategy":"try-catch","validationCode":"record = db.get_analysis_history_by_id(source_report_id)\nif record is None:\n    return JSONResponse(status_code=404, content={\"error\": \"source_report_not_found\", \"message\": f\"report {source_report_id} not found\"})\nresult = service.reassess(source_report_id=source_report_id, decision_profile=profile)","typeGuard":"def isExistingReport(db, report_id: int) -> bool:\n    return db.get_analysis_history_by_id(report_id) is not None","tryCatchPattern":"from src.services.decision_signal_reassess_service import DecisionSignalSourceReportNotFoundError\n\ntry:\n    result = service.reassess(source_report_id=rid, decision_profile=profile, persist=persist)\nexcept DecisionSignalSourceReportNotFoundError:\n    return JSONResponse(status_code=404, content={\"error\": \"source_report_not_found\", \"message\": f\"report {rid} not found\"})","preventionTips":["Only offer reassess on reports returned by the history list of the same environment.","Handle history-retention pruning: expired ids should 404 gracefully in the UI.","Validate the id is a positive int before calling."],"tags":["decision-signal","reassess","not-found"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}