Skip to content

Commit

Permalink
Merge pull request #566 from UdeshAthukorala/concurrent-patch
Browse files Browse the repository at this point in the history
Fix unique key violation exception when concurrent group patch requests trying to add same users to the group
  • Loading branch information
UdeshAthukorala authored Aug 5, 2024
2 parents 204fd0f + 8ad91c9 commit 6168312
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3391,6 +3391,16 @@ public void updateGroup(Group oldGroup, Group newGroup) throws CharonException,
try {
doUpdateGroup(oldGroup, newGroup);
} catch (UserStoreException e) {
if (e instanceof org.wso2.carbon.user.core.UserStoreException && (StringUtils
.equals(UserCoreErrorConstants.ErrorMessages.ERROR_CODE_DUPLICATE_WHILE_WRITING_TO_DATABASE
.getCode(), ((org.wso2.carbon.user.core.UserStoreException) e).getErrorCode()) ||
StringUtils.equals(UserCoreErrorConstants.ErrorMessages
.ERROR_CODE_DUPLICATE_WHILE_UPDATING_USER_OF_ROLE.getCode(),
((org.wso2.carbon.user.core.UserStoreException) e).getErrorCode()))) {
// This handles the scenario where a unique key violation exception occurs when concurrent group
// patch requests try to add the same users to the group.
return;
}
handleErrorsOnRoleNamePolicy(e);
throw resolveError(e, e.getMessage());
} catch (IdentitySCIMException e) {
Expand Down Expand Up @@ -3659,6 +3669,16 @@ public Group updateGroup(Group oldGroup, Group newGroup, Map<String, Boolean> re
return oldGroup;
}
} catch (UserStoreException e) {
if (e instanceof org.wso2.carbon.user.core.UserStoreException && (StringUtils
.equals(UserCoreErrorConstants.ErrorMessages.ERROR_CODE_DUPLICATE_WHILE_WRITING_TO_DATABASE
.getCode(), ((org.wso2.carbon.user.core.UserStoreException) e).getErrorCode()) ||
StringUtils.equals(UserCoreErrorConstants.ErrorMessages
.ERROR_CODE_DUPLICATE_WHILE_UPDATING_USER_OF_ROLE.getCode(),
((org.wso2.carbon.user.core.UserStoreException) e).getErrorCode()))) {
// This handles the scenario where a unique key violation exception occurs when concurrent group
// patch requests try to add the same users to the group.
return getGroup(newGroup.getId(), requiredAttributes);
}
handleErrorsOnRoleNamePolicy(e);
throw resolveError(e, e.getMessage());
} catch (IdentitySCIMException e) {
Expand Down

0 comments on commit 6168312

Please sign in to comment.