Skip to content

Segment update endpoint accepts duplicate names within the same ledger #1956

@gandalf-at-lerian

Description

@gandalf-at-lerian

Description:
The PATCH /v1/organizations/:org_id/ledgers/:ledger_id/segments/:id endpoint does not validate name uniqueness, allowing two segments in the same ledger to end up with identical names.

Root cause:
UpdateSegmentByID in components/onboarding/internal/services/command/update-segment.go:24 goes straight to uc.SegmentRepo.Update() without calling FindByName first. The create path (create-segment.go:58) already performs this check.

Expected behavior:
When renaming a segment to a name already taken by another segment in the same org/ledger, the API should return 409 with error code 0015 ("Duplicate Segment Name Error").

Actual behavior:
The API returns 200 and silently accepts the duplicate name.

Suggested fix:
Add a FindByName check in UpdateSegmentByID when upi.Name is non-empty, excluding the segment being updated (by ID) from the uniqueness check.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions