infiniflow/ragflow · error · AdminException

400

400

Error message

Exist more than 1 user: {username}!

What it means

AdminException (HTTP 400) raised by UserServiceMgr.get_user_datasets (admin/server/services.py:241) when the email matches multiple user rows. The listing derives tenant ids from user_list[0]; with duplicates it could return another account's knowledge bases, so the ambiguous query is refused.

Source

Thrown at admin/server/services.py:241

            raise AdminException(f"Exist more than 1 user: {username}!")
        # check activate status different from new
        usr = user_list[0]
        if not usr.is_superuser:
            return f"{usr} isn't superuser, yet!"
        # update is_active
        UserService.update_user(usr.id, {"is_superuser": False})
        return "Revoke successfully!"


class UserServiceMgr:
    @staticmethod
    def get_user_datasets(username):
        # use email to find user.
        user_list = UserService.query_user_by_email(username)
        if not user_list:
            raise UserNotFoundError(username)
        elif len(user_list) > 1:
            raise AdminException(f"Exist more than 1 user: {username}!")
        # find tenants
        usr = user_list[0]
        tenants = TenantService.get_joined_tenants_by_user_id(usr.id)
        tenant_ids = [m["tenant_id"] for m in tenants]
        # filter permitted kb and owned kb
        return KnowledgebaseService.get_all_kb_by_tenant_ids(tenant_ids, usr.id)

    @staticmethod
    def get_user_agents(username):
        # use email to find user.
        user_list = UserService.query_user_by_email(username)
        if not user_list:
            raise UserNotFoundError(username)
        elif len(user_list) > 1:
            raise AdminException(f"Exist more than 1 user: {username}!")
        # find tenants
        usr = user_list[0]
        tenants = TenantService.get_joined_tenants_by_user_id(usr.id)

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Enumerate duplicates: SELECT id, email FROM user WHERE email = '<username>';
  2. Dedupe to a single row per email.
  3. Add a unique constraint on the email column.
  4. Retry the dataset listing.

Example fix

-- before
SELECT COUNT(*) FROM user WHERE email='user@example.com';  -- >1, listing fails
-- after
DELETE FROM user WHERE email='user@example.com' AND id <> '<intended-id>';
ALTER TABLE user ADD UNIQUE KEY uq_user_email (email);
Defensive patterns

Strategy: validation

Validate before calling

from api.db.services import UserService

def assert_unique_target(email: str) -> None:
    users = UserService.query_user_by_email(email)
    if len(users) != 1:
        raise RuntimeError(f'{email}: {len(users)} rows; dataset listing ambiguous')

Try / catch

from admin.server.exceptions import AdminException
try:
    kbs = UserServiceMgr.get_user_datasets(email)
except AdminException as e:
    if 'more than 1 user' in e.message.lower():
        raise RuntimeError('duplicate users; dedupe before listing datasets') from e
    raise

Prevention

When it happens

Trigger: Duplicate user rows share one email; every get_user_datasets call for that address fails before TenantService is consulted.

Common situations: Imported/migrated data with duplicated accounts; no unique index on email; concurrent provisioning races during first SSO login.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/f177f754368d740a. Report an issue: GitHub.