FINERACT-248: Prevent duplicate SMS campaign names#5439
Open
nickus wants to merge 1 commit intoapache:developfrom
Open
FINERACT-248: Prevent duplicate SMS campaign names#5439nickus wants to merge 1 commit intoapache:developfrom
nickus wants to merge 1 commit intoapache:developfrom
Conversation
Add validation to check for duplicate campaign names before creating or updating SMS campaigns. This provides a user-friendly error message instead of relying on database constraint violations. Changes: - Add existsByCampaignName() and existsByCampaignNameAndIdNot() to repository - Validate campaign name uniqueness in create() method - Validate campaign name uniqueness in update() when name changes - Add SmsCampaignNameAlreadyExistsException for clear error messages - Add integration tests for duplicate name validation - Update CampaignsHelper with methods for testing specific campaign names
bc4e52c to
a8a8b7a
Compare
galovics
requested changes
Feb 6, 2026
Comment on lines
+113
to
+115
| if (this.smsCampaignRepository.existsByCampaignName(campaignName)) { | ||
| throw new SmsCampaignNameAlreadyExistsException(campaignName); | ||
| } |
Contributor
There was a problem hiding this comment.
I think the default isolation level we use is read_committed, meaning only committed things will be revealed by this check. It not guarantees anything.
2 transactions concurrently writing the same campaign name is possible.
If you wanna prevent it, ensure having a unique key on the DB level. This is good for a best-effort check but it's not bullet-proof,.
Author
There was a problem hiding this comment.
Actually, there is already a unique key on the DB level. You might see further I catch DataIntegrityViolationException and throw the same exception.
see realCause.getMessage().contains("campaign_name_UNIQUE")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add validation to check for duplicate campaign names before creating or updating SMS campaigns. This provides a user-friendly error message instead of relying on database constraint violations.
Changes
existsByCampaignName()andexistsByCampaignNameAndIdNot()methods toSmsCampaignRepositorycreate()method before savingupdate()method when name changesSmsCampaignNameAlreadyExistsExceptionfor clear error messagesTest plan