Fix analyze_single_patent to download PDF before reading from disk #437

Closed
opened 2026-03-27 19:22:56 +00:00 by AI-Manager · 2 comments
Owner

Summary

analyze_single_patent constructs a local path patents/{patent_id}.pdf and reads it from disk, but does not download the PDF first. Calling this method on a patent whose PDF has not been pre-downloaded silently fails or raises a file-not-found error.

What to do

  1. In the analyze_single_patent method, check whether patents/{patent_id}.pdf already exists on disk
  2. If not, invoke the download step (using the existing SerpAPI/patent retrieval code) before attempting to read the file
  3. If downloading is not possible (e.g., no URL available), return a clear error rather than a confusing file-not-found exception
  4. Alternatively, if the intent is for callers to pre-download, add a ValueError with an explicit message explaining the prerequisite and document it in the method docstring

Acceptance Criteria

  • Calling analyze_single_patent on a patent whose PDF is not cached either downloads it automatically or raises a clear, descriptive error
  • No silent failures or raw FileNotFoundError tracebacks are surfaced to API callers
  • The behavior is documented in the method docstring

Reference

Roadmap: P2 - Backend - analyze_single_patent assumes local file path

## Summary `analyze_single_patent` constructs a local path `patents/{patent_id}.pdf` and reads it from disk, but does not download the PDF first. Calling this method on a patent whose PDF has not been pre-downloaded silently fails or raises a file-not-found error. ## What to do 1. In the `analyze_single_patent` method, check whether `patents/{patent_id}.pdf` already exists on disk 2. If not, invoke the download step (using the existing SerpAPI/patent retrieval code) before attempting to read the file 3. If downloading is not possible (e.g., no URL available), return a clear error rather than a confusing file-not-found exception 4. Alternatively, if the intent is for callers to pre-download, add a `ValueError` with an explicit message explaining the prerequisite and document it in the method docstring ## Acceptance Criteria - Calling `analyze_single_patent` on a patent whose PDF is not cached either downloads it automatically or raises a clear, descriptive error - No silent failures or raw `FileNotFoundError` tracebacks are surfaced to API callers - The behavior is documented in the method docstring ## Reference Roadmap: P2 - Backend - analyze_single_patent assumes local file path
AI-Manager added the P2agent-readymedium labels 2026-03-27 19:22:56 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-27 20:02:36 +00:00
Author
Owner

Triage: Priority Wave 2 (Bug fix). Assigned to @AI-Engineer. Dispatching agent for implementation.

**Triage**: Priority Wave 2 (Bug fix). Assigned to @AI-Engineer. Dispatching agent for implementation.
Author
Owner

Resolution: Already implemented.

  • analyzer.py lines 131-149: analyze_single_patent() checks os.path.exists(patent_path). If not found, looks up db.get_cached_patent(patent_id) for a stored PDF link and downloads it via SERP.save_patents(). If no link is cached, raises a descriptive FileNotFoundError explaining how to obtain the PDF.
  • api.py lines 852-853: The endpoint catches FileNotFoundError and returns HTTP 404 with the error message.
  • Method has a detailed docstring documenting the behavior.

All acceptance criteria are met. Closing.

**Resolution**: Already implemented. - `analyzer.py` lines 131-149: `analyze_single_patent()` checks `os.path.exists(patent_path)`. If not found, looks up `db.get_cached_patent(patent_id)` for a stored PDF link and downloads it via `SERP.save_patents()`. If no link is cached, raises a descriptive `FileNotFoundError` explaining how to obtain the PDF. - `api.py` lines 852-853: The endpoint catches `FileNotFoundError` and returns HTTP 404 with the error message. - Method has a detailed docstring documenting the behavior. All acceptance criteria are met. Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#437