Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unique key violation exception when concurrent group patch requests trying to add same users to the group #566

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading