Skip to content

Conversation

@pablohashescobar
Copy link
Member

@pablohashescobar pablohashescobar commented Dec 8, 2025

Description

  • correct created by in workspace seed data

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Test Scenarios

  • create a new workspace and verify the created_by's for various entities

References

WEB-5598

Summary by CodeRabbit

  • New Features
    • Bot user is now automatically added to workspaces during initialization.
    • Objects created during workspace setup now properly record their creator attribution.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 8, 2025 13:10
@makeplane
Copy link

makeplane bot commented Dec 8, 2025

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Walkthrough

The 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 create() calls with two-step constructor-then-save patterns, enabling explicit user attribution and bot user workspace membership during initialization.

Changes

Cohort / File(s) Summary
Configuration retrieval formatting
apps/api/plane/app/views/workspace/base.py
Reformatted get_configuration_value call from multiline list to single-line list; no functional change to DISABLE_WORKSPACE_CREATION logic.
ORM creation pattern refactoring
apps/api/plane/bgtasks/workspace_seed_task.py
Replaced direct ORM create() calls with constructor instantiation followed by save(disable_auto_set_user=True) across Project, State, Label, Issue, Page, ProjectPage, Cycle, Module, IssueView, and related associations. Added bot user membership assignment to workspace during seed task initialization.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify the two-step constructor-then-save pattern is applied consistently across all model instantiations in workspace_seed_task.py
  • Confirm that disable_auto_set_user=True flag is correctly set in all save() calls and that user attribution is properly recorded
  • Validate bot user membership initialization logic and ensure it integrates correctly with existing workspace seeding workflow

Poem

🐰 A rabbit hops through workspace seeds,
Planting objects with user deeds,
Two steps now, not one by one,
Bot friends join when tasks are done! 🌱

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title references the main changes: streamlining object creation in workspace seed task and improving error handling, which align with the code changes in both modified files.
Description check ✅ Passed The description is minimal but covers key required sections: description of the bug fix, type of change, test scenarios, and references to the issue. However, it lacks detailed explanation of the changes and screenshots are not applicable.
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-workspace-seed-created-by

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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_by fields 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7659997 and 4f02a0c.

📒 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_id in the constructor, then calling save() with both created_by_id and disable_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_id attribution.


224-230: LGTM!

Label creation correctly uses the two-step pattern with proper created_by_id attribution.


277-284: LGTM!

Issue creation correctly uses the two-step pattern with proper created_by_id attribution.


353-378: LGTM!

Both Page and ProjectPage creation correctly use the two-step pattern with proper created_by_id attribution. 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_id attribution. The dynamic date calculation logic is also appropriate.


455-463: LGTM!

Module creation correctly uses the two-step pattern with proper created_by_id attribution.


484-492: LGTM!

IssueView creation correctly uses the two-step pattern with proper created_by_id attribution.

Copy link
Contributor

Copilot AI left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants