-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: duplicate the uploaded assets for duplicated page #6311
base: preview
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request introduces a new mechanism for handling asset duplication during page or entity copying. A new background task ( Changes
Sequence DiagramsequenceDiagram
participant User
participant PageDuplicateEndpoint
participant CopyS3ObjectTask
participant S3Storage
User->>PageDuplicateEndpoint: Request page duplication
PageDuplicateEndpoint->>CopyS3ObjectTask: Trigger copy_s3_objects.delay()
CopyS3ObjectTask->>CopyS3ObjectTask: Extract asset IDs
CopyS3ObjectTask->>S3Storage: Copy S3 objects
CopyS3ObjectTask->>CopyS3ObjectTask: Update HTML descriptions
CopyS3ObjectTask-->>PageDuplicateEndpoint: Return duplicated assets
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
apiserver/plane/bgtasks/copy_s3_object.py (3)
34-40
: Caution: swallowing exceptions can mask underlying errors.
This function returns an empty list if parsing fails, potentially hiding issues involving malformed HTML or BeautifulSoup usage. Consider logging the exception or re-raising it to facilitate troubleshooting.
62-78
: Add request timeouts and handle unexpected responses.
Using a timeout parameter inrequests.post(...)
would help avoid indefinite waits if the external service is slow. Also consider handling unexpected response formats or status codes for enhanced resilience.
80-143
: Handle concurrency and address line-length warnings.
- This Celery task can race with other tasks for the same entity. If multiple tasks try to copy assets concurrently, unexpected duplicates or data inconsistencies could appear. Consider gating tasks, or verifying if a task for the same entity is already in progress.
- Several lines exceed 88 characters (e.g., lines 85, 86, 105). Complying with line-length standards can improve readability and pass automated lint checks.
Below is a suggested way to split line 105 as an example:
- destination_key = f"{workspace.id}/{uuid.uuid4().hex}-{original_asset.attributes.get('name')}" + asset_name = original_asset.attributes.get("name") + destination_key = f"{workspace.id}/{uuid.uuid4().hex}-{asset_name}"🧰 Tools
🪛 Ruff (0.8.2)
85-85: Line too long (104 > 88)
(E501)
86-86: Line too long (101 > 88)
(E501)
105-105: Line too long (106 > 88)
(E501)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apiserver/plane/app/views/page/base.py
(2 hunks)apiserver/plane/bgtasks/copy_s3_object.py
(1 hunks)apiserver/plane/settings/common.py
(1 hunks)apiserver/plane/settings/storage.py
(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Build and Lint on Pull Request
apiserver/plane/settings/common.py
[error] 176-176: Line too long (90 > 88 characters)
🪛 Ruff (0.8.2)
apiserver/plane/bgtasks/copy_s3_object.py
85-85: Line too long (104 > 88)
(E501)
86-86: Line too long (101 > 88)
(E501)
105-105: Line too long (106 > 88)
(E501)
🔇 Additional comments (7)
apiserver/plane/bgtasks/copy_s3_object.py (3)
17-31
: Consider raising an error or logging more information for unrecognized entity types.
By returning an empty dictionary ifentity_type
is not found, the caller may not detect that an unsupported type was used. Incorporating at least a warning log or raising an explicit exception could help pinpoint issues early.
42-52
: Replacement logic looks correct; watch out for partial matches.
Currently, the logic replacessrc
attributes only when there's an exact match. Ensure that unintended partial matches (e.g., query parameters) don't occur, or handle them separately if needed.
54-59
: Consider concurrency or versioning for shared entities.
Whenupdate_description
is called by multiple tasks in parallel, the last update might overwrite earlier changes. If concurrency is a concern, consider implementing an optimistic locking strategy or a revision check.apiserver/plane/settings/storage.py (1)
155-167
: Copy logic is well-structured; consider verifying source object existence.
Thecopy_object
method uses a try-except block to handleClientError
, but you could also verify that the source object exists before attempting the copy. This would allow for more specific error messages and reduce reliance on exception-handling as flow control.apiserver/plane/settings/common.py (1)
339-340
: Verify that the LIVE_BASE_URL is properly set for all environments.
Ensure that this new environment variable is set in each deployment environment, or handle cases when it’s absent to prevent failures in external service calls.apiserver/plane/app/views/page/base.py (2)
42-42
: Import statement is correct.
Bringing incopy_s3_objects
here is in line with the asynchronous task usage.
590-599
: Ensure error handling for the asynchronous duplication task.
Thecopy_s3_objects.delay(...)
call does not track success or failure once initiated. Consider providing a callback or updating relevant logs/fields so you can track and alert the user if asset copying fails.
Description
this pull request ensures assets are duplicated along with the page during duplication.
Type of Change
References
Summary by CodeRabbit
New Features
Improvements