Fix double upload bug and improve test #663
Merged
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.
In our deployment we have been encountering a bug that happens when:
/upload/
route.We observe that in the second upload, we get a 409, which is good. However, we also find that the binary package file is still updated on the server, even though the http request was rejected. The repodata is not updated, as expected. This means that we get hash mismatch errors because the incorrectly updated binary does not agree with the correct hashes for the original file in the repodata.
I think the problem is here, where we call
pkgstore.add_package_async
before the try/except block that ultimately results in the 409.During debugging I found that the other upload route is also affected.
Changes in this PR:
/channels/{channel_name}/packages/{package_name}/files/
, the upload is handled through a call tohandle_package_files
, which in turn uses_extract_and_upload_package
. I added aforce
argument and a file existence check to_extract_and_upload_package
, which is then transformed into an HTTP 409 inhandle_package_files
/channels/{channel_name}/upload/{filename}
, the solution is more straightforward as the call topkgstore.add_package_async
happens right in the top-level function. I moved the call after the try/except block that checks for 409.Expected test failure before fix here