Conversation
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
added 2 commits
October 6, 2026 14:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First of all, very much appreciate what you guys are doing here! We're implementing InvenTree right now and will most probably come up with some ideas and PRs in the future as we can allocate some capacity for bringing this project forward :)
Problem
With media stored in S3, every data import fails on session creation with HTTP 500, also reported by another user in #11117.
This affects all supported formats, because the failing line runs before any format specific code.
Cause
After
DataImportSession.save(),self.data_fileis a freshFieldFileanddata_file.fileopens it through the storage backend in moderb.load_data_file()then callsopen('r')on it. When configuring S3, theS3File.open()raises when the requested mode differs from the one the file was opened with. Django'sFile.open()(local storage) only seeks to the start if the file is already open and ignores the requested mode, so the bug never shows locally.Fix
Open the file in binary mode. The function already decodes text formats itself (utf-8-sig with cp1252 fallback) and passes Excel data to tablib as bytes, so binary is what the code expects. Behaviour with local file storage is unchanged.
Testing
After
DataImportSession.save(),self.data_fileis a freshFieldFileanddata_file.fileopens it through the storage backend in moderb.load_data_file()then callsopen('r')on it. django-storages'S3File.open()raises when the requested mode differs from the one the file was opened with. Django'sFile.open()(local storage) only seeks to the start if the file is already open and ignores the requested mode, so the bug never shows locally.Testing
Reproduced on InvenTree 1.5.6 (Python 3.14, django-storages 1.14.6) with media on real S3:
POST /api/importer/session/with a csv and an xlsx both return 500 with the error above. The file is already uploaded, so each attempt leaves an orphaned session in stateINITIALplus its file in the bucket.