plane icon indicating copy to clipboard operation
plane copied to clipboard

[WEB-4428] fix: duplicate labels

Open sangeethailango opened this issue 4 months ago • 2 comments

Description

This PR will validate label names to avoid duplicates.

Type of Change

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [x] Code refactoring

sangeethailango avatar Jul 11 '25 07:07 sangeethailango

[!CAUTION]

Review failed

The pull request is closed.

[!NOTE]

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Added case-insensitive, project-scoped duplicate-name validation to LabelSerializer; updated label create/partial_update endpoints to pass project context and perform explicit serializer validation; added unit tests for valid creation and duplicate-name rejection.

Changes

Cohort / File(s) Summary
Label Serializer Validation
apps/api/plane/app/serializers/issue.py
Added validate_name(self, value) to LabelSerializer to enforce case-insensitive uniqueness of label names within a project, excluding the current instance during updates; raises ValidationError with "LABEL_NAME_ALREADY_EXISTS" on duplicates.
Label View Integration
apps/api/plane/app/views/issue/label.py
Passes context={"project_id": project_id} when instantiating LabelSerializer in create() and partial_update(); partial_update() now builds/validates/saves the serializer explicitly instead of delegating to the parent method; minor formatting tweak in BulkCreateIssueLabelsEndpoint.
Serializer Tests
apps/api/plane/tests/unit/serializers/test_label.py
Added TestLabelSerializer with test_label_serializer_create_valid_data (successful create) and test_label_serializer_create_duplicate_name (duplicate rejected with "LABEL_NAME_ALREADY_EXISTS" error).

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant LabelView
    participant LabelSerializer
    participant Database

    rect rgb(230, 245, 255)
    Note over Client,Database: Label create/update flow (project-scoped validation)
    Client->>LabelView: POST / PATCH label data
    LabelView->>LabelSerializer: Instantiate with data + context {project_id}
    LabelSerializer->>Database: Query labels where project_id == X (case-insensitive name check)
    alt Duplicate found
        Database-->>LabelSerializer: Existing label(s)
        LabelSerializer-->>LabelView: ValidationError "LABEL_NAME_ALREADY_EXISTS"
        LabelView-->>Client: 400 Error (validation)
    else No duplicate
        LabelSerializer->>Database: Save label
        Database-->>LabelSerializer: Persisted label
        LabelSerializer-->>LabelView: Serialized response
        LabelView-->>Client: 200/201 Success
    end
    end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the case-insensitive comparison and queryset filtering in validate_name.
  • Verify exclusion of the current instance in update flows.
  • Confirm project_id is reliably provided via view context in all call sites and tests.

Poem

🐇 I hopped through fields of labels bright,
Found twins and set them to the right.
Project-wise I guard each name,
No duplicates now; order reclaimed. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title '[WEB-4428] fix: duplicate labels' clearly and specifically summarizes the main change - adding validation to prevent duplicate label names.
Description check ✅ Passed The PR description includes a clear description of the changes, identifies the change type (bug fix and code refactoring), and provides detailed implementation notes. However, it lacks screenshots/media and explicit test scenarios section.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 602251c309913e6083324719ac71876aed554eb2 and 4638ce199f4b477d9230379e7e047b284a76e162.

📒 Files selected for processing (2)
  • apps/api/plane/app/serializers/issue.py (1 hunks)
  • apps/api/plane/app/views/issue/label.py (3 hunks)

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.

coderabbitai[bot] avatar Jul 11 '25 07:07 coderabbitai[bot]

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

makeplane[bot] avatar Jul 11 '25 07:07 makeplane[bot]