Skip to content

Fix 500 on .lua file upload from closed-file write#47

Merged
joefarrelly merged 1 commit into
devfrom
fix-upload-closed-file
Jun 30, 2026
Merged

Fix 500 on .lua file upload from closed-file write#47
joefarrelly merged 1 commit into
devfrom
fix-upload-closed-file

Conversation

@joefarrelly

Copy link
Copy Markdown
Owner

Summary

  • ProfileUserView.perform_update validated and rewrote the uploaded .lua file in place via with file.open("r+") as f: ..., which closes the underlying stream on exit. The closed file was then passed to serializer.save(), which crashed when the storage backend tried to read it again (ValueError: I/O operation on closed file) — this hit every upload, not just large ones, since Django's InMemoryUploadedFile doesn't override File.close().
  • Reads and validates the content once, then saves a fresh ContentFile built from the normalised bytes instead of reusing the original (now-closed) upload stream.

Test plan

  • Added a regression test that reproduces the exact ValueError against the pre-fix code and passes against the fix
  • pytest tests/ (34 passed)
  • ruff check

perform_update closed the uploaded file's stream via a context manager
before handing it to the storage backend, which then failed trying to
re-read it. Validate and normalise the content directly, then save it
as a fresh ContentFile instead of reusing the original upload stream.
@joefarrelly joefarrelly enabled auto-merge (squash) June 30, 2026 22:58
@joefarrelly joefarrelly merged commit 6700fe3 into dev Jun 30, 2026
3 checks passed
@joefarrelly joefarrelly deleted the fix-upload-closed-file branch June 30, 2026 22:58
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
apicore/views.py 75.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

2 participants