+
Skip to content

Uncaught server error during organization update when name already exists #39179

@pjahn-cinemo

Description

@pjahn-cinemo

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

organizations

Describe the bug

Discovered via admin api via PUT /admin/realms/{realm}/organizations/{org-id}, but also shows in admin ui:

When creating a new organization with a name that already exists an appropriate error with http status 409 is returned

{
    "errorMessage": "A organization with the same name already exists."
}

When updating an organization, changing the name to one that already exists, a generic error with http status 500 is returned

{ 
    "error": "unknown_error",
    "error_description": "For more on this error consult the server log."
}

and server logs show an unhandled exception:

2025-04-24 09:59:22,709 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-417) Uncaught server error: org.hibernate.exception.ConstraintViolationException: could not execute batch [Batch entry 0 update public.ORG set ALIAS=('testorg123'),DESCRIPTION=(''),ENABLED=('TRUE'::boolean),GROUP_ID=('e230bf45-dae9-484a-9d99-d2d5dff77e20'),NAME=('123 123'),REALM_ID=('testrealm'),REDIRECT_URL=(NULL) where ID=('62096c46-64ae-4e1d-95e6-d3c4fb3b57c0') was aborted: ERROR: duplicate key value violates unique constraint "uk_org_name"

Version

26.2.1

Regression

  • The issue is a regression

Expected behavior

When updating an organization with PUT /admin/realms/{realm}/organizations/{org-id}, using a name that already exists, an appropriate error and status code that is consistent with a similar situation while creating an organization is returned.

Actual behavior

Updating returns a generic error while creating returns a specific error.

How to Reproduce?

  • create 2 organizations
  • try to update one organization using the name of the other
  • observe error messages and server log

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载