fix: handle server-side S3 storage initialization for generic assets#8773
fix: handle server-side S3 storage initialization for generic assets#8773vvaswani wants to merge 1 commit intomakeplane:previewfrom
Conversation
Signed-off-by: Vikram Vaswani <2571660+vvaswani@users.noreply.github.com>
|
|
📝 WalkthroughWalkthroughUpdates Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can disable the changed files summary in the walkthrough.Disable the |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
apps/api/plane/settings/storage.py (2)
46-55: Add a fail-fast guard for MinIO endpoint configuration.When
USE_MINIO=1, missingAWS_S3_ENDPOINT_URL/MINIO_ENDPOINT_URLcan silently create a client against unintended defaults. Prefer explicit validation and an early error.Proposed patch
if os.environ.get("USE_MINIO") == "1": # Determine protocol based on environment variable if os.environ.get("MINIO_ENDPOINT_SSL") == "1": endpoint_protocol = "https" else: endpoint_protocol = request.scheme if request else "http" endpoint_url = self.aws_s3_endpoint_url if request and not is_server: endpoint_url = f"{endpoint_protocol}://{request.get_host()}" + if not endpoint_url: + raise ValueError("AWS_S3_ENDPOINT_URL or MINIO_ENDPOINT_URL must be set when USE_MINIO=1") # Create an S3 client for MinIO self.s3_client = boto3.client(🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/api/plane/settings/storage.py` around lines 46 - 55, When MinIO is enabled, add a fail-fast check before creating self.s3_client to ensure the MinIO endpoint is explicitly configured (i.e., aws_s3_endpoint_url / MINIO_ENDPOINT_URL present) and raise a clear error (ValueError/RuntimeError) if it's missing; update the logic around endpoint_url (which currently computes endpoint_protocol and may override with request.get_host()) to validate that when USE_MINIO (or the instance flag that enables MinIO) is true, endpoint_url is not empty/None and abort construction of the boto3.client with a descriptive error instead of letting boto3 use defaults. Ensure you modify the block that sets endpoint_url and the self.s3_client initialization so the guard runs before boto3.client is called.
25-55: Please add regression tests for endpoint selection branches.This logic now controls whether presigned URLs use internal endpoint vs request host. Add targeted tests for
(request present, is_server=True),(request present, is_server=False), and(request absent)underUSE_MINIO=1to lock in behavior and prevent future 500 regressions.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/api/plane/settings/storage.py` around lines 25 - 55, Add regression tests targeting the storage settings initializer behavior in the class with __init__ (the constructor shown in apps/api/plane/settings/storage.py) to cover endpoint selection under USE_MINIO=1: create three tests for (1) request present and is_server=True, (2) request present and is_server=False, and (3) request absent; each test should set environment vars (USE_MINIO=1 and relevant MINIO/AWS envs), provide a stub/mocked request with scheme and get_host where needed, instantiate the class, and assert the resolved endpoint_url used to construct boto3.client (or the resulting s3_client.endpoint_url / stored aws_s3_endpoint_url) matches the expected value (internal MINIO endpoint vs request host vs default), cleaning up env changes between tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/api/plane/settings/storage.py`:
- Around line 46-55: When MinIO is enabled, add a fail-fast check before
creating self.s3_client to ensure the MinIO endpoint is explicitly configured
(i.e., aws_s3_endpoint_url / MINIO_ENDPOINT_URL present) and raise a clear error
(ValueError/RuntimeError) if it's missing; update the logic around endpoint_url
(which currently computes endpoint_protocol and may override with
request.get_host()) to validate that when USE_MINIO (or the instance flag that
enables MinIO) is true, endpoint_url is not empty/None and abort construction of
the boto3.client with a descriptive error instead of letting boto3 use defaults.
Ensure you modify the block that sets endpoint_url and the self.s3_client
initialization so the guard runs before boto3.client is called.
- Around line 25-55: Add regression tests targeting the storage settings
initializer behavior in the class with __init__ (the constructor shown in
apps/api/plane/settings/storage.py) to cover endpoint selection under
USE_MINIO=1: create three tests for (1) request present and is_server=True, (2)
request present and is_server=False, and (3) request absent; each test should
set environment vars (USE_MINIO=1 and relevant MINIO/AWS envs), provide a
stub/mocked request with scheme and get_host where needed, instantiate the
class, and assert the resolved endpoint_url used to construct boto3.client (or
the resulting s3_client.endpoint_url / stored aws_s3_endpoint_url) matches the
expected value (internal MINIO endpoint vs request host vs default), cleaning up
env changes between tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cb6143c8-639e-46c7-8d00-3bbc5a4dccc4
📒 Files selected for processing (1)
apps/api/plane/settings/storage.py
Description
Fixes a 500 error in the generic asset API by updating S3Storage to accept the existing is_server=True argument used by GenericAssetEndpoint methods.
Type of Change
Test Scenarios
References
Fixes #8680
Summary by CodeRabbit