Skip to content

fix(oss): return 404 when file large object is missing - #7362

Open
ump45nose wants to merge 1 commit into
1Panel-dev:v2from
ump45nose:fix/7356-missing-large-object-404
Open

ump45nose wants to merge 1 commit into
1Panel-dev:v2from
ump45nose:fix/7356-missing-large-object-404

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Summary

Fixes #7356.

When a file row still exists but its PostgreSQL large object (loid) has already been removed, File.get_bytes() → lo_get raises DatabaseError (large object … does not exist). FileSerializer.Operate.get() used to let that bubble up as HTTP 500 with the raw database message.

This change catches that specific error and raises NotFound404 with a short “File content not found” message, matching the existing “File not found” path for a missing row. Other DatabaseErrors are rethrown unchanged.

Test plan

  • Unit regression in apps/oss/tests.py (MissingLargeObjectTests):
    • missing large object → NotFound404 (status 404)
    • unrelated DatabaseError → still raised
  • Locally verified the same mapping with a stubbed import of FileSerializer.Operate.get (full MaxKB Django stack / Postgres not available in this environment).
  • Not run: full project test suite / live Docker reproduce with lo_unlink.

AI assistance disclosure

An AI coding assistant helped implement the catch, the unit tests, and this PR description. I reviewed the diff and the local regression results above.

When the file row still exists but PostgreSQL lo_get fails with
"large object … does not exist", map that to NotFound404 instead of
leaking the database error as HTTP 500.

Fixes 1Panel-dev#7356
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