Repository navigation
fix: upload every chunk once in LargeFileUploadTask - #1172
Open
nabeleon94 wants to merge 1 commit into
Open
nabeleon94 wants to merge 1 commit into
nabeleon94 wants to merge 1 commit into
Conversation
upload() appended "-" to the service's nextExpectedRanges value and then
parsed the empty end with int(), so every upload larger than one chunk
failed with "invalid literal for int() with base 10: ''". The error was
logged and swallowed for the middle chunks, and raised from last_chunk().
Uploads that fit in one chunk sent the same range a second time after the
session had completed, which the service rejects with a 400.
upload() now walks the file from the next expected range, sends each
chunk once, uses last_chunk() only for the final chunk, and lets upload
errors propagate. Open-ended ranges ("100-" or "100") are parsed with a
missing end treated as 0, as next_chunk() and last_chunk() already expect.
|
This branch has not been deployed
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.



Overview
Fixes microsoftgraph/msgraph-sdk-python#1631. Also fixes #718 (and microsoftgraph/msgraph-sdk-python#1067).
LargeFileUploadTask.upload()fails for any file larger than one chunk, and it errors after the upload has already finished for files that fit in one chunk.self.next_range = next_range[0] + "-". The service sendsnextExpectedRangesas"535313"(Outlook) or"535313-"(OneDrive), sonext_chunk()/last_chunk()then read an empty end and calledint(''). TheValueErrorwas logged and swallowed for the middle chunks, so no further chunks were sent, andlast_chunk()then raisedinvalid literal for int() with base 10: ''. That is the traceback in #1631.next_chunk()before the loop, and thechunks == 0iteration then sent the same range again throughlast_chunk(). By then the session was complete, so the service returned the 400 inLargeFileUploadTask.upload()throws a 400 error when file size is smaller than max_chunk_size #718 / chore(deps): consolidate all dependabot updates #1067.Changes
upload()now starts at the next expected range (0 for a new session, the stored range forresume()). It sends each chunk once, useslast_chunk()only for the final chunk soitem_responsestill holds the parsed item, and continues from the service'snextExpectedRanges. Upload errors now propagate instead of being logged and dropped._parse_range()helper handles"0-99","100-"and"100"(and a list), treating a missing end as 0.next_chunk()andlast_chunk()already read 0 as "up to one chunk from start". Those two methods use it instead of their duplicatedint()parsing.loggingimport is removed.Testing Instructions
tests/tasks/test_large_file_upload.py. It uses a fake upload session that checks eachContent-Rangeagainst the bytes it has received, rejects PUTs after completion, and answersnextExpectedRangesin both the Outlook ("N") and OneDrive ("N-") forms.item_response/locationare set.resume()from"640-"and"640"continues at byte 640._parse_rangecases.main, 14 of the 14 upload/resume tests fail: 8 withValueError: invalid literal for int() with base 10: ''and 6 with the PUT-after-completion error. With this change, all 18 pass.pytest tests: 102 passed. The 4test_graph_client_factory.pyfailures happen onmaintoo in my environment and are unrelated.yapf -dr src,isorton the changed file,pylint(10.00/10 on the file) andmypy(no new findings) are clean.