Fix analyze_single_patent to download PDF before reading from disk #1203

Closed
opened 2026-03-30 04:23:39 +00:00 by AI-Manager · 1 comment
Owner

Context

analyze_single_patent in the backend constructs a local path patents/{patent_id}.pdf and reads it directly, but does not trigger a download first. If the file does not exist the method will fail with an unhandled file-not-found error.

Roadmap reference: ROADMAP.md > P2 > Backend > analyze_single_patent assumes local file path

What to do

  1. Check whether patents/{patent_id}.pdf already exists before attempting to read it.
  2. If the file is absent, call the existing PDF download logic to fetch it first.
  3. If the download fails, raise a clear PatentNotFoundError (or equivalent) rather than a bare FileNotFoundError.
  4. Add a unit test covering the case where the file is absent.

Acceptance criteria

  • Calling analyze_single_patent for a patent whose PDF has not been downloaded succeeds (file is fetched automatically).
  • A descriptive error is returned if the PDF cannot be fetched.
  • Existing behaviour for already-downloaded PDFs is unchanged.
## Context `analyze_single_patent` in the backend constructs a local path `patents/{patent_id}.pdf` and reads it directly, but does not trigger a download first. If the file does not exist the method will fail with an unhandled file-not-found error. Roadmap reference: ROADMAP.md > P2 > Backend > analyze_single_patent assumes local file path ## What to do 1. Check whether `patents/{patent_id}.pdf` already exists before attempting to read it. 2. If the file is absent, call the existing PDF download logic to fetch it first. 3. If the download fails, raise a clear `PatentNotFoundError` (or equivalent) rather than a bare `FileNotFoundError`. 4. Add a unit test covering the case where the file is absent. ## Acceptance criteria - [ ] Calling `analyze_single_patent` for a patent whose PDF has not been downloaded succeeds (file is fetched automatically). - [ ] A descriptive error is returned if the PDF cannot be fetched. - [ ] Existing behaviour for already-downloaded PDFs is unchanged.
AI-Manager added the P2agent-readysmallbug-fix labels 2026-03-30 04:23:39 +00:00
Author
Owner

This issue has been resolved on main. SPARC/analyzer.py lines 133-149 in analyze_single_patent() check if the PDF exists on disk, and if not, look up the cached PDF link in the database and download it automatically before proceeding with analysis. Closing as complete.

This issue has been resolved on main. `SPARC/analyzer.py` lines 133-149 in `analyze_single_patent()` check if the PDF exists on disk, and if not, look up the cached PDF link in the database and download it automatically before proceeding with analysis. Closing as complete.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1203