Repository navigation
Return 4xx when file download storage blob is missing - #15371
Conversation
Guard file_api.download() after fallback storage lookup so missing blobs return a structured error instead of make_response(None). Fixes infiniflow#15369
📝 WalkthroughWalkthroughThe file download handler now checks after both primary and fallback storage lookups; if the blob remains missing, it logs a warning and returns an error response with "This file is empty." A unit test was added to verify both lookup attempts and the error response. ChangesEmpty Blob Guard in File Download
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 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 `@api/apps/restful_apis/file_api.py`:
- Around line 302-303: The new empty-blob return path in file_api.py silently
returns get_error_data_result when "if not blob" is true; add a warning log
immediately before that return (e.g., logger.warning or
current_app.logger.warning) including the file identifier (file_id), tenant
context (tenant_id or request tenant), and a short message like "storage lookup
returned empty blob" so storage lookup failures are traceable; update the block
around the "if not blob" check to log these identifiers and any available
request/context info, then return get_error_data_result as before.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bb844acf-1452-4277-ae34-759f6555c148
📒 Files selected for processing (2)
api/apps/restful_apis/file_api.pytest/testcases/test_web_api/test_file_app/test_file_routes_unit.py
|
Actionable comments posted: 0 |
|
@yuzhichang @JinHai-CN Is there any way to manually trigger the CI? |
|
@JinHai-CN @yingfeng @yuzhichang Can any one of you help to trigger CI? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15371 +/- ##
==========================================
- Coverage 94.56% 93.16% -1.40%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 668 -10
- Misses 25 29 +4
- Partials 14 20 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Fixes #15369 —
GET /api/v1/files/<file_id>callsmake_response(None)when both primary and fallback storage lookups return empty, causing HTTP 500.Related Issue
Fixes #15369
Change Type
What Changed
file_api.download()— after fallbackSTORAGE_IMPL.get, returnget_error_data_result(message="This file is empty.")whennot blob, matching document REST download semantics.Files Changed
api/apps/restful_apis/file_api.pymake_response()test/testcases/test_web_api/test_file_app/test_file_routes_unit.pyValidation
cd /root/gittensor/ragflow pytest test/testcases/test_web_api/test_file_app/test_file_routes_unit.py::test_download_missing_blob_returns_error -v pytest test/testcases/test_web_api/test_file_app/test_file_routes_unit.py::test_download_falls_back_to_document_storage -vTest Plan
"This file is empty."(nomake_response(None))