Skip to content

fix(oss): return 404 when a file's stored data is missing - #7891

Open
shu-chen-dot-ca wants to merge 1 commit into
1Panel-dev:v2from
shu-chen-dot-ca:fix-7356-missing-large-object
Open

shu-chen-dot-ca wants to merge 1 commit into
1Panel-dev:v2from
shu-chen-dot-ca:fix-7356-missing-large-object

Conversation

@shu-chen-dot-ca

Copy link
Copy Markdown

Fixes #7356

When a file row still exists but its PostgreSQL large object is gone, lo_get fails with SQLSTATE 42704 and /oss/file/<id> answered {"code": 500, "message": "large object N does not exist"} (with HTTP 200). FileSerializer.Operate.get() now catches that one error and raises the same NotFound404(404, 'File not found') already used when the row itself is missing. Any other DatabaseError is re-raised unchanged. No new translation string is needed.

Tested on a local v2 setup (PostgreSQL 17 + pgvector, Redis): I uploaded a file, ran lo_unlink on its loid (the steps in the issue), then requested the file:

  • /admin/oss/file/<id> and /chat/oss/file/<id> now return HTTP 404 "File not found" (before: code 500 with the raw database message)
  • a .mp3 file requested with a Range header gets the same 404
  • two file rows that share one large object (same sha256) both get 404 after it is removed
  • healthy files still return 200 (206 for ranged audio)
  • other database errors raised while reading (undefined table 42P01, division by zero 22012) are still re-raised as before
  • ruff check apps/oss/serializers/file.py and typos apps/oss pass
Before After
before after

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 知识库图片访问返回 500:large object 90563 does not exist

1 participant