Repository navigation
OpenConceptLab/ocl_issues#2991 | Azure storage uploads file objects and raises on failure - #1003
Conversation
…nd raises on failure BlobStorage had no upload(), so every caller fell through to the interface stub and got None (MapProject.update_input_file never recorded the file). Add upload() with the S3/MinIO contract (204, raise on failure), drop the bare except in _upload so failures are no longer swallowed, and add contract tests over S3, MinIO and Azure.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
snyaggarwal
left a comment
There was a problem hiding this comment.
I’d address the export cleanup regression before merging. The new Azure upload fixes the missing 204 that map projects depend on. The importer still needs an authenticated read path for private Azure containers.
| OCL behavior | S3 | MinIO | Azure in this PR |
|---|---|---|---|
upload(stream) |
Boto3 managed upload, returns 204 |
put_object, returns 204. Uses remaining length or 10 MiB parts for an unknown-length stream. |
upload_blob(overwrite=True), returns 204. The SDK handles stream length and chunking. |
| Stream content type | Forwards metadata as ExtraArgs; ignores headers |
Header, then metadata.ContentType, then extension, then octet-stream |
Same precedence as MinIO |
upload_file(path) |
Returns 204 |
Returns object name | Returns blob URL. ZIP exports still get the legacy Content-Encoding: zip. |
upload_base64 with valid input |
Returns file name. The public ACL path still catches NoCredentialsError. |
Returns file name. Wraps SDK S3Error. |
Returns file name on success. SDK upload exceptions now propagate. |
url_for |
Presigned GET | Presigned GET | Unsigned URL |
The remaining upload return-value and metadata differences are already tracked in #3042. SDK references: Boto3 managed uploads, MinIO stream uploads, Azure Blob uploads.
I reproduced the CSV working-directory leak by running the actual export helper with an injected upload exception. The Azure, S3, and MinIO comparison is based on source and SDK docs.
…irectory and remove their temp files write_export_file and write_csv_to_s3 change the process working directory before uploading. An upload that raises (now also on Azure) skipped os.chdir(cwd) and the temp cleanup. write_export_file now restores the directory and removes the temp files in a finally around the whole export; write_csv_to_s3 restores the directory in a finally. Regression tests assert the upload exception reaches the caller.
…so private containers can be read The importer fetches cached inputs over plain HTTP through url_for(). Azure returned an unsigned URL, so an upload could succeed and the import still fail against a private container (the Azure default). url_for now returns a one-week read-only SAS URL for the blob, carrying the download name when given, and keeps the unsigned URL when the connection has no account key. Storage failure tests use a dedicated exception so they cannot pass on an unrelated error.
|
Review round on 6b336ec, addressed in two new commits (no amend) on top of the current branch head:
The three review threads have a reply and are resolved. The PR body has the new root causes, decisions and verification numbers. Not covered: a real Azure Storage account (Azurite only), |
snyaggarwal
left a comment
There was a problem hiding this comment.
Approving at 63ef027. All three items from my Nov 20 review are fixed as your replies describe:
- Export cleanup:
write_export_filenow runs the export inside atry/finally. Thefinallyrestores the working directory and removes the temp directorycd_temp()created (the same one the old code removed), and that also covers the export's early returns and a failed serialization.write_csv_to_s3restores the directory in afinallybefore re-raising. The tests check that the dedicatedExportUploadFailurereaches the caller and thatos.getcwd()is unchanged. - Private containers:
url_forsigns a read-only SAS (sp=r, 7 days like the S3 and MinIO presigned URLs) when the connection has an account key, and carries the download name throughcontent_disposition_header. Without a key, it keeps the unsigned URL. Every caller (export downloads, map project and repo files, the importer's cached inputs) builds the URL when it's requested and none stores it, so the expiry matches S3's. Thanks for the Azurite round trip: 409 unsigned, 200 signed, 403 tampered. - Tests: the dedicated
UploadFailureandExportUploadFailureexceptions close the false-green path.
upload() streams with the same content-type precedence as MinIO, and _upload no longer swallows errors. That matches S3: a failed upload_base64, such as a logo, now raises instead of saving a name for a blob that was never written.
The branch is 23 commits behind master but merges cleanly. The only change to these files since (#985 in core/common/utils.py) is in other functions. CI was green on Nov 20. I haven't run the tests.
Fine as follow-ups: copy() still passes an unsigned source URL (same-account Shared Key copies don't need a SAS, but a SAS-only connection would), the CSV temp directory is still left behind as before, and the shared _put() refactor stays with #3042.
TL;DR: The Azure storage backend now has
upload()with the same contract as S3 and MinIO (returns204, raises on failure), so map project input files, import files and repo files are stored on Azure instead of being silently dropped. Because failures now raise, exports clean up after a failed upload, andurl_for()signs reads so the importer can fetch from a private container.Closes OpenConceptLab/ocl_issues#2991
Scope started as Azure only, as agreed: the single
_put()hook per backend from the issue's "Possible solution" is deferred to a follow-up PR tracked in OpenConceptLab/ocl_issues#3042, and no S3 or MinIO storage code (#973, #975) is touched.Scope grew during review
The original fix was the Azure
upload()plus letting its failures raise. Review of 6b336ec (@snyaggarwal) found two consequences of that fix that this PR now also covers, so its scope is wider than in its first version:core/common/utils.pywrite_export_file/write_csv_to_s3then skippedos.chdir(cwd)and the temp cleanupfinallyalso covers failed uploads and failed serialization on S3 and MinIO, where the same flaw already existed. Behavior on success is unchangedc07beb11url_for()inazure.pyurl_for()over plain HTTP, so an upload that now succeeds would still fail to import from a private container (the Azure default)rscd) instead of unsigned. A connection without an account key keeps the unsigned URL63ef0278Also from review, test-only: dedicated
UploadFailure/ExportUploadFailureexceptions so failure-propagation tests cannot pass on an unrelated error.Still out of scope: see "Out of scope" below.
Root cause
BlobStorage(core/services/storages/cloud/azure.py) had noupload(). Everyservice.upload(...)call fell through to the emptyCloudStorageServiceInterface.uploadstub and returnedNone.MapProject.update_input_filerequiresresult == 204, so on Azureinput_file_namewas never saved. Importer uploads (importers/views.py,importers/importer.py) andrepos/models.pysilently stored nothing.BlobStorage._uploadwrapped everything in a bareexceptand returnedNone, so a failed upload was invisible, andupload_base64still returned the file name after a swallowed failure.write_export_fileandwrite_csv_to_s3(core/common/utils.py) skippedos.chdir(cwd)and the temp cleanup, because both change the process working directory before uploading. The same flaw already existed on S3 and MinIO.url_for()over plain HTTP. Azure'surl_for()returned an unsigned URL, so against a private container (the Azure default) an upload could succeed and the import still fail.Main Changes
upload()core/services/storages/cloud/azure.pyupload(key, file_content, headers, metadata): streams the file object withupload_blob(overwrite=True)and returns204.core/services/storages/cloud/azure.pyexceptremoved from_upload;upload_fileandupload_base64now raise on failure like S3/MinIO.core/services/storages/cloud/azure.pyupload()resolves it from headers, then S3-styleContentTypemetadata, then the key extension, thenapplication/octet-stream(same precedence asMinIO.upload).core/services/storages/cloud/azure.pyurl_for()returns a one-week read-only SAS URL (with the download name when given); a connection without an account key keeps the unsigned URL.core/common/utils.pywrite_export_filerestores the working directory and removes its temp files in afinallyaround the whole export (body renamed_write_export_file);write_csv_to_s3restores the directory in afinally.core/services/storages/cloud/tests.py,core/common/tests.pyBlobStorageTestupload andurl_forcases;StorageUploadContractTestover S3, MinIO and Azure with a dedicatedUploadFailure; export and CSV cleanup tests with a dedicatedExportUploadFailure.Totals by
git diff --numstat origin/master...HEAD: 4 files, +354/-52.Key Decisions
_put()refactor widens risk and is left for a second PR (as the issue recommends). The two review additions are consequences of making Azure uploads raise and succeed.upload()content settingsContent-Encoding_uploadturnsapplication/octet-streamintoContent-Encoding: octet-stream, which is wrong for import files._upload's behaviour forupload_fileis unchanged (an existing test pins it).S3Error; wrapping adds nothing for Azure.upload_file/upload_base64now raise instead of returningNoneupload()never worked, so no working flow depends on the silent failure. Export zips (common/utils.py) now fail visibly.MinIO.__content_typefinallyinwrite_export_file(whole export) andwrite_csv_to_s3Out of scope (follow-up: OpenConceptLab/ocl_issues#3042)
upload_filereturn values still differ (Azure blob URL, MinIO object name, S3204); only logged or ignored by callers._put()hook per backend inCloudStorageServiceInterface, with one shared content type resolution (replaces the copy ofMinIO.__content_typeadded here).public_readis honored only by S3 today.Not changed here:
BlobStorage.copy()still passes an unsigned source URL tostart_copy_from_url; the resource report incore/reports/models.pyusescd_temp()without uploading; the CSV temp directory is still not removed.Verification
url_for)core.common.tests core.services core.map_projects: 392 tests, 8 failures. 6 are the same failuresmastershows in this container (5 inOpenIDAuthServiceTest,MinIOTest.test_minio_client_instantiated_with_env_vars; identicalFAIL:set onmaster, checked by stashing the first round of changes). The other 2 (MapProjectListViewTest.test_post,MapProjectViewTest.test_put) patchaws.S3.uploadwhile the container uses MinIO; withEXPORT_SERVICE=...aws.S3core.map_projectspasses (108 tests, OK)git diff --checkcleanget_export_service()withEXPORT_SERVICE=...azure.BlobStorage, 10/10 checks, re-run after the last commit:MapProject.update_input_filerecordsinput_file_name(savemocked, no DB rows written) and the blob holds the bytestext/csv, no content encoding204,application/octet-stream, no content encodingupload_base64returnslogo.pngand stores it;upload_filestores the exportupload,upload_file,upload_base64against a missing container raiseResourceNotFoundErrormaster:input_file_namestays empty and the blob does not exist (reproduces #2991)url_for->requests.get(stream=True)->ImporterUtils.fetch_to_file), 8/8 checks: upload204; unsigned URL HTTP 409; signedurl_forURL HTTP 200 with the uploaded bytes; tampered signature and another blob's signature HTTP 403;filenamebecomesContent-Disposition: attachment; filename="my export.zip"Probe output (excerpt):