Find an already-created PDF reading report by its stable source key.
(
user_id: str,
request_metadata: Dict[str, Any],
fallback_paper: Dict[str, Any],
)
| 1392 | |
| 1393 | def _lookup_existing_pdf_report( |
| 1394 | user_id: str, |
| 1395 | request_metadata: Dict[str, Any], |
| 1396 | fallback_paper: Dict[str, Any], |
| 1397 | ) -> Optional[Dict[str, Any]]: |
| 1398 | """Find an already-created PDF reading report by its stable source key.""" |
| 1399 | source_type = _clean_text(request_metadata.get("report_source_type")) |
| 1400 | source_key = _clean_text(request_metadata.get("report_source_key")) |
| 1401 | if not source_type or not source_key: |
| 1402 | return None |
| 1403 | |
| 1404 | report_record = get_recent_created_report_by_source(user_id, source_type, source_key) |
| 1405 | if not report_record: |
| 1406 | return None |
| 1407 | if not _is_report_record_current(report_record): |
| 1408 | return None |
| 1409 | if not _report_record_matches_language(report_record, request_metadata.get("response_language")): |
| 1410 | return None |
| 1411 | |
| 1412 | return _build_reused_doc_entry(fallback_paper, report_record) |
| 1413 | |
| 1414 | |
| 1415 | def _merge_paper_details(base: Dict[str, Any], detail: Dict[str, Any]) -> Dict[str, Any]: |
| 1416 | merged = dict(base) |
no test coverage detected