feat: add sheet upload jobs to Python SDK#11
Conversation
📝 WalkthroughWalkthroughChangesSheet PDF upload support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant HVAKRClient
participant SheetFilesAPI
participant JobAPI
Caller->>HVAKRClient: create_sheet_file(project_id, file, file_name)
HVAKRClient->>HVAKRClient: Validate and normalize PDF content
HVAKRClient->>SheetFilesAPI: POST multipart sheet file
SheetFilesAPI-->>HVAKRClient: Return sheet-upload job
HVAKRClient-->>Caller: Return APIJob
Caller->>JobAPI: get_job(job_id)
JobAPI-->>Caller: Return upload result and page readiness
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/hvakr/client.py`:
- Around line 126-130: Update the file-content loading logic near the sheet
upload validation to bound file-like reads: preserve direct bytes handling, but
call read with MAX_API_SHEET_UPLOAD_BYTES + 1 for BinaryIO inputs so the
existing length check can detect oversize content without loading it fully into
memory. Keep the TypeError and ValueError behavior unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 1d85022d-57b9-4435-a7a7-2961db65f75e
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (7)
README.mdpyproject.tomlsrc/hvakr/__init__.pysrc/hvakr/client.pysrc/hvakr/schemas/__init__.pysrc/hvakr/schemas/api.pytests/test_client.py
| content = file if isinstance(file, bytes) else file.read() | ||
| if not isinstance(content, bytes): | ||
| raise TypeError("Sheet upload file must provide bytes.") | ||
| if len(content) > MAX_API_SHEET_UPLOAD_BYTES: | ||
| raise ValueError("Sheet PDF exceeds the 30 MiB API upload limit.") |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Bound file-like reads before enforcing the upload limit.
file.read() loads an arbitrarily large BinaryIO into memory before line 129 rejects it. Read at most MAX_API_SHEET_UPLOAD_BYTES + 1 bytes so oversized streams cannot exhaust process memory.
Proposed fix
- content = file if isinstance(file, bytes) else file.read()
+ content = (
+ file
+ if isinstance(file, bytes)
+ else file.read(MAX_API_SHEET_UPLOAD_BYTES + 1)
+ )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| content = file if isinstance(file, bytes) else file.read() | |
| if not isinstance(content, bytes): | |
| raise TypeError("Sheet upload file must provide bytes.") | |
| if len(content) > MAX_API_SHEET_UPLOAD_BYTES: | |
| raise ValueError("Sheet PDF exceeds the 30 MiB API upload limit.") | |
| content = ( | |
| file | |
| if isinstance(file, bytes) | |
| else file.read(MAX_API_SHEET_UPLOAD_BYTES + 1) | |
| ) | |
| if not isinstance(content, bytes): | |
| raise TypeError("Sheet upload file must provide bytes.") | |
| if len(content) > MAX_API_SHEET_UPLOAD_BYTES: | |
| raise ValueError("Sheet PDF exceeds the 30 MiB API upload limit.") |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/hvakr/client.py` around lines 126 - 130, Update the file-content loading
logic near the sheet upload validation to bound file-like reads: preserve direct
bytes handling, but call read with MAX_API_SHEET_UPLOAD_BYTES + 1 for BinaryIO
inputs so the existing length check can detect oversize content without loading
it fully into memory. Keep the TypeError and ValueError behavior unchanged.
Summary
Validation
Release this as 0.6.1 after the API deployment is live.
Summary by CodeRabbit
New Features
Improvements