Repository navigation
fix: call super().__init__() in S3Storage so location is set - #9942
Conversation
- `S3Storage` never called `super().__init__()`, so django-storages state such as `location` and `bucket_name` was never set up. - Because `S3Storage` is `STORAGES["default"]`, every direct FileField upload failed with `AttributeError: 'S3Storage' object has no attribute 'location'`. - Add a unit test checking that the base attributes are initialised.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The targeted fix correctly initializes inherited storage state and includes focused regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Initializes the django-storages base class so S3Storage works with Django FileField operations.
Changes:
- Calls
super().__init__()to initialize inherited storage state. - Adds regression coverage for
locationand path normalization.
| File | Description |
|---|---|
apps/api/plane/settings/storage.py |
Initializes the base S3 storage implementation. |
apps/api/plane/tests/unit/settings/test_storage.py |
Verifies required inherited attributes and normalization. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ation # Conflicts: # apps/api/plane/tests/unit/settings/test_storage.py
With super().__init__() in place, S3Storage works as the default FileField storage again, so the legacy multipart routes (workspace and user file-assets, issue-attachments) accept uploads. - S3Storage sets default_acl = None, so a FileField upload sends no canned ACL whatever AWS_DEFAULT_ACL says. - FileAssetSerializer and IssueAttachmentSerializer reject an uploaded file whose declared content type is missing or outside ATTACHMENT_MIME_TYPES, or that is larger than FILE_SIZE_LIMIT, as the presigned routes do.
sriramveeraghanta
left a comment
There was a problem hiding this comment.
LGTM now. The legacy multipart POSTs validate against ATTACHMENT_MIME_TYPES and FILE_SIZE_LIMIT, and default_acl = None takes precedence over AWS_DEFAULT_ACL (django-storages only fills in settings the class doesn't define). Unit tests pass locally (13/13). Note: the legacy attachment DELETE now really removes the S3 object, which seems right.
fix(api): port makeplane#9942 (S3Storage super init, legacy upload validation) and eight-digit sign-up and email-change codes
Description
S3Storageis configured asSTORAGES["default"], but its__init__never calledsuper().__init__(). As a result django-storages state such aslocationwas never set, and any directFileFieldsave raisedAttributeError: 'S3Storage' object has no attribute 'location'.This PR calls
super().__init__()at the start ofS3Storage.__init__so the base class initialises its own attributes. The existing credential/bucket setup that follows is unchanged.Making direct saves work again also brings back the three legacy multipart upload routes (
FileAssetEndpoint.post,UserAssetsEndpoint.post,IssueAttachmentEndpoint.post), so this PR hardens them the same way the presigned (v2) routes are:S3Storage.default_acl = None:FileFielduploads send no canned ACL, whateverAWS_DEFAULT_ACLsays. Objects keep the bucket's default access and are read through presigned URLs.FileAssetSerializerandIssueAttachmentSerializerreject an uploaded file whose declared content type is missing or not inATTACHMENT_MIME_TYPES, or that is larger thanFILE_SIZE_LIMIT, with a 400. One shared function,validate_uploaded_file, covers all three routes. It only runs on upload input; read responses and the v2 routes are unaffected.previewand kept bothTestS3StorageDefaultStorageandTestS3StorageObjectMetadataintest_storage.py.Notes for review:
ATTACHMENT_MIME_TYPESincludesimage/svg+xml,text/xmlandapplication/xml, as it does for the v2 routes. The protection for those is that the object is not publicly readable and downloads are forced toattachment.AWS_DEFAULT_ACL = "public-read"insettings/common.pyno longer has any effect and can be removed in a follow-up.Type of Change
Screenshots and Media (if applicable)
Test Scenarios
TestS3StorageDefaultStorageassertsS3Storage().location == "", that_normalize_nameworks, and that_get_write_parameterscarries noACLeven withAWS_DEFAULT_ACL = "public-read".test_legacy_upload_validation_app.pycovers each of the three legacy routes:text/htmland an empty declared type return 400, an oversize file returns 400,image/pngreturns 201.docker compose -f docker-compose-test.yml run --rm api-tests pytest plane/tests/unit/settings/test_storage.py plane/tests/contract/app/test_legacy_upload_validation_app.py(56 passed together with the existing legacy-route tests; full API suite 1711 passed).References
N/A
Created with Claude Code
Summary by CodeRabbit