Skip to content

Return 4xx when file download storage blob is missing - #15371

Merged
yingfeng merged 2 commits into
infiniflow:mainfrom
kiannidev:fix/15369-file-download-missing-blob
Jun 1, 2026
Merged

yingfeng merged 2 commits into
infiniflow:mainfrom
kiannidev:fix/15369-file-download-missing-blob

Conversation

@kiannidev

@kiannidev kiannidev commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #15369 — GET /api/v1/files/<file_id> calls make_response(None) when both primary and fallback storage lookups return empty, causing HTTP 500.

Related Issue

Fixes #15369

Change Type

  • Bug fix
  • Regression tests

What Changed

  • file_api.download() — after fallback STORAGE_IMPL.get, return get_error_data_result(message="This file is empty.") when not blob, matching document REST download semantics.

Files Changed

File Change
api/apps/restful_apis/file_api.py Empty-blob guard before make_response()
test/testcases/test_web_api/test_file_app/test_file_routes_unit.py Regression test

Validation

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 -v

Test Plan

  • Both storage paths empty → "This file is empty." (no make_response(None))
  • Existing fallback success test still passes
  • CI green

Guard file_api.download() after fallback storage lookup so missing
blobs return a structured error instead of make_response(None).
Fixes infiniflow#15369
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐖api The modified files are located under directory 'api/apps/sdk' 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels May 28, 2026
@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Empty Blob Guard in File Download

Layer / File(s) Summary
Empty blob guard implementation and test
api/apps/restful_apis/file_api.py, test/testcases/test_web_api/test_file_app/test_file_routes_unit.py
download adds a falsy check after primary and fallback STORAGE_IMPL.get attempts and returns get_error_data_result(message="This file is empty.") when blob remains missing. A unit test test_download_missing_blob_returns_error mocks storage get to return None, verifies both lookup attempts, and asserts the error message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • #15369: File download returns HTTP 500 when storage blob is missing — this PR implements the described guard to avoid make_response(None).

Poem

🐰 In burrows of bytes a file went thin,
I hopped by and checked, then saved us from sin.
If the blob is gone, I shout with a cheer:
"This file is empty." — no 500s here. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main change: returning a 4xx error when file download storage blob is missing, which directly addresses the issue.
Linked Issues check ✅ Passed The PR fully addresses the primary objective from issue #15369: adding an empty-blob guard after fallback storage lookup to return get_error_data_result instead of calling make_response(None), with regression test included.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #15369: modifications to file_api.py download function and a corresponding regression test. No unrelated changes detected.
Description check ✅ Passed The PR description covers all required template sections with clear problem statement, change type, and specific implementation details.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7fc909a and 12923b9.

📒 Files selected for processing (2)
  • api/apps/restful_apis/file_api.py
  • test/testcases/test_web_api/test_file_app/test_file_routes_unit.py

Comment thread api/apps/restful_apis/file_api.py Resolved
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@xugangqiang xugangqiang self-assigned this May 29, 2026
@xugangqiang xugangqiang added ci Continue Integration and removed ci Continue Integration labels May 29, 2026
@xugangqiang

Copy link
Copy Markdown
Contributor

@yuzhichang @JinHai-CN Is there any way to manually trigger the CI?

@xugangqiang

Copy link
Copy Markdown
Contributor

@JinHai-CN @yingfeng @yuzhichang Can any one of you help to trigger CI?

@yingfeng
yingfeng marked this pull request as draft May 29, 2026 09:27
@yingfeng
yingfeng marked this pull request as ready for review May 29, 2026 09:27
@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (7fc909a) to head (93baae9).
⚠️ Report is 8 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xugangqiang

xugangqiang commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

LGTM
@yuzhichang @yingfeng @JinHai-CN

@xugangqiang
xugangqiang requested a review from yingfeng June 1, 2026 10:55
@yingfeng
yingfeng merged commit b35266e into infiniflow:main Jun 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐖api The modified files are located under directory 'api/apps/sdk' 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: GET /api/v1/files/<file_id> returns HTTP 500 when storage blob is missing

3 participants