-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[WEB-5598] refactor: streamline object creation in workspace seed task and improve error handling in workspace creation #8264
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
base: preview
Are you sure you want to change the base?
Conversation
…ve error handling in workspace creation
|
Linked to Plane Work Item(s) This comment was auto-generated by Plane |
WalkthroughThe changes comprise two distinct updates: a minor formatting refactor of configuration retrieval in workspace view creation, and a significant refactoring of object creation patterns in workspace seed tasks to replace single-step ORM Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/api/plane/bgtasks/workspace_seed_task.py (1)
285-331: Inconsistent object creation for issue-related entities.While the Issue itself has been refactored to use the two-step pattern (lines 277-284), the following related entities still use the direct
.create()method:
- IssueSequence (line 285)
- IssueActivity (line 292)
- IssueLabel (lines 304-310)
- CycleIssue (lines 314-320)
- ModuleIssue (lines 325-331)
For consistency with the PR's objective to correctly set
created_byfields throughout workspace seed data, these should also be refactored to use the instantiate-then-save pattern:# Example for IssueSequence issue_sequence = IssueSequence( issue=issue, project_id=project_map[project_id], workspace_id=workspace.id, created_by_id=bot_user.id, ) issue_sequence.save(created_by_id=bot_user.id, disable_auto_set_user=True)Apply similar changes to IssueActivity, IssueLabel, CycleIssue, and ModuleIssue.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/api/plane/app/views/workspace/base.py(1 hunks)apps/api/plane/bgtasks/workspace_seed_task.py(12 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: dheeru0198
Repo: makeplane/plane PR: 7625
File: apps/api/plane/bgtasks/workspace_seed_task.py:95-98
Timestamp: 2025-09-12T07:29:36.083Z
Learning: In the Plane codebase, workspace seed data should have project features (cycle_view, module_view, issue_views_view) enabled by default, even when regular project creation has these features disabled. This provides users with a complete demo experience in the seeded workspace.
Learnt from: NarayanBavisetti
Repo: makeplane/plane PR: 7460
File: apps/api/plane/app/serializers/draft.py:112-122
Timestamp: 2025-07-23T18:18:06.875Z
Learning: In the Plane codebase serializers, workspace_id is not consistently passed in serializer context, so parent issue validation in DraftIssueCreateSerializer only checks project_id rather than both workspace_id and project_id. The existing project member authentication system already validates that users can only access projects they belong to, providing sufficient security without risking breaking functionality by adding workspace_id validation where the context might not be available.
📚 Learning: 2025-09-12T07:29:36.083Z
Learnt from: dheeru0198
Repo: makeplane/plane PR: 7625
File: apps/api/plane/bgtasks/workspace_seed_task.py:95-98
Timestamp: 2025-09-12T07:29:36.083Z
Learning: In the Plane codebase, workspace seed data should have project features (cycle_view, module_view, issue_views_view) enabled by default, even when regular project creation has these features disabled. This provides users with a complete demo experience in the seeded workspace.
Applied to files:
apps/api/plane/bgtasks/workspace_seed_task.py
📚 Learning: 2025-07-23T18:18:06.875Z
Learnt from: NarayanBavisetti
Repo: makeplane/plane PR: 7460
File: apps/api/plane/app/serializers/draft.py:112-122
Timestamp: 2025-07-23T18:18:06.875Z
Learning: In the Plane codebase serializers, workspace_id is not consistently passed in serializer context, so parent issue validation in DraftIssueCreateSerializer only checks project_id rather than both workspace_id and project_id. The existing project member authentication system already validates that users can only access projects they belong to, providing sufficient security without risking breaking functionality by adding workspace_id validation where the context might not be available.
Applied to files:
apps/api/plane/bgtasks/workspace_seed_task.py
🧬 Code graph analysis (1)
apps/api/plane/bgtasks/workspace_seed_task.py (6)
apps/api/plane/db/models/project.py (4)
Project(65-159)save(157-159)save(169-171)save(208-218)apps/api/plane/db/models/state.py (1)
State(75-122)apps/api/plane/db/models/issue.py (1)
Issue(108-254)apps/api/plane/db/models/page.py (1)
Page(19-73)apps/api/plane/db/models/cycle.py (1)
Cycle(56-97)apps/api/plane/db/models/module.py (1)
Module(63-123)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Lint API
- GitHub Check: Agent
- GitHub Check: Analyze (javascript)
🔇 Additional comments (9)
apps/api/plane/app/views/workspace/base.py (1)
78-83: Minor formatting change with no functional impact.The tuple unpacking syntax has been reformatted from
DISABLE_WORKSPACE_CREATION,to(DISABLE_WORKSPACE_CREATION,). Both forms are equivalent and the behavior remains unchanged.apps/api/plane/bgtasks/workspace_seed_task.py (8)
97-108: Correct implementation of two-step object creation.The Project creation properly follows the new pattern: instantiating the model with
created_by_idin the constructor, then callingsave()with bothcreated_by_idanddisable_auto_set_user=True. This ensures proper attribution of the created_by field.
191-197: LGTM!State creation correctly uses the two-step pattern with proper
created_by_idattribution.
224-230: LGTM!Label creation correctly uses the two-step pattern with proper
created_by_idattribution.
277-284: LGTM!Issue creation correctly uses the two-step pattern with proper
created_by_idattribution.
353-378: LGTM!Both Page and ProjectPage creation correctly use the two-step pattern with proper
created_by_idattribution. The conditional logic for PROJECT type pages is also handled appropriately.
418-427: LGTM!Cycle creation correctly uses the two-step pattern with proper
created_by_idattribution. The dynamic date calculation logic is also appropriate.
455-463: LGTM!Module creation correctly uses the two-step pattern with proper
created_by_idattribution.
484-492: LGTM!IssueView creation correctly uses the two-step pattern with proper
created_by_idattribution.
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.
Pull request overview
This PR refactors the workspace seed task to correctly set the created_by field for seeded entities by using a bot user, and improves code formatting in the workspace creation endpoint. The changes address an issue where the created_by field was not properly set during workspace seeding.
Key Changes
- Modified object creation pattern from
.objects.create()to constructor +.save(created_by_id=bot_user.id, disable_auto_set_user=True)for proper created_by attribution - Added WorkspaceMember creation for the bot user to ensure it's a member of the workspace
- Applied minor formatting improvements to workspace creation code
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/api/plane/bgtasks/workspace_seed_task.py | Refactored object creation for Project, State, Label, Issue, Page, ProjectPage, Cycle, Module, and IssueView to use constructor + save() pattern with disable_auto_set_user flag; added bot user as workspace member |
| apps/api/plane/app/views/workspace/base.py | Reformatted get_configuration_value call for better readability (formatting only) |
Comments suppressed due to low confidence (1)
apps/api/plane/bgtasks/workspace_seed_task.py:290
- Duplicate IssueSequence creation detected. The Issue model's save() method already creates an IssueSequence automatically (see apps/api/plane/db/models/issue.py:238), but this code is creating another IssueSequence manually. This will result in two IssueSequence records being created for each issue.
Since the Issue.save() method handles the IssueSequence creation internally, this manual creation should be removed to avoid duplicates.
IssueSequence.objects.create(
issue=issue,
project_id=project_map[project_id],
workspace_id=workspace.id,
created_by_id=bot_user.id,
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Type of Change
Test Scenarios
References
WEB-5598
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.