infiniflow/ragflow · error · AdminException

Invalid activate_status: {activate_status}

Error message

Invalid activate_status: {activate_status}

What it means

AdminException (HTTP 400) raised by UserMgr.update_user_activate_status (admin/server/services.py:146) when activate_status.lower() is neither 'on' nor 'off'. The mapping table only accepts those two exact strings; anything else has no target ActiveEnum value and is rejected before the user record is touched.

Source

Thrown at admin/server/services.py:146

    @staticmethod
    def update_user_activate_status(username, activate_status: str):
        # use email to find user. check exist and unique.
        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}!")
        # check activate status different from new
        usr = user_list[0]
        # format activate_status before handle
        _activate_status = activate_status.lower()
        target_status = {
            "on": ActiveEnum.ACTIVE.value,
            "off": ActiveEnum.INACTIVE.value,
        }.get(_activate_status)
        if not target_status:
            raise AdminException(f"Invalid activate_status: {activate_status}")
        if target_status == usr.is_active:
            return f"User activate status is already {_activate_status}!"
        # update is_active
        update_dict = {"is_active": target_status}
        if target_status == ActiveEnum.INACTIVE.value:
            update_dict["access_token"] = f"INVALID_{secrets.token_hex(16)}"
        UserService.update_user(usr.id, update_dict)
        return f"Turn {_activate_status} user activate status successfully!"

    @staticmethod
    def get_user_api_key(username: str) -> list[dict[str, Any]]:
        # use email to find user. check exist and unique.
        user_list: list[Any] = UserService.query_user_by_email(username)
        if not user_list:
            raise UserNotFoundError(username)
        elif len(user_list) > 1:
            raise AdminException(f"More than one user with username '{username}' found!")

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Use exactly 'on' or 'off' (any case) for activate_status.
  2. Map your script's booleans explicitly: str(flag).lower() in {'true','1','yes'} -> 'on', else 'off'.
  3. Validate the parameter client-side before calling and fail with a clear message.
  4. Check for typos or shell-quoting issues that pass an empty/garbled value.

Example fix

# before
UserMgr.update_user_activate_status(email, 'true')  # 400 Invalid activate_status

# after
status = 'on' if ENABLED else 'off'
assert status in ('on', 'off')
UserMgr.update_user_activate_status(email, status)
Defensive patterns

Strategy: validation

Validate before calling

def normalize_activate_status(value: str) -> str:
    v = str(value).strip().lower()
    mapping = {'true': 'on', '1': 'on', 'yes': 'on', 'active': 'on',
               'false': 'off', '0': 'off', 'no': 'off', 'inactive': 'off'}
    status = mapping.get(v, v)
    if status not in ('on', 'off'):
        raise ValueError(f'activate_status must be on/off, got {value!r}')
    return status

Type guard

def is_valid_activate_status(value: str) -> bool:
    return isinstance(value, str) and value.strip().lower() in ('on', 'off')

Try / catch

from admin.server.exceptions import AdminException
try:
    UserMgr.update_user_activate_status(email, status)
except AdminException as e:
    if e.message.startswith('Invalid activate_status'):
        raise ValueError('use exactly "on" or "off"') from e
    raise

Prevention

When it happens

Trigger: Passing 'true'/'false', '1'/'0', 'active'/'inactive', 'enable'/'disable', or an empty string as activate_status; uppercase is fine because the value is lowercased first, but synonyms are not translated.

Common situations: Automation written against a different API's vocabulary; boolean flags stringified as 'True'; unset environment variables defaulting to empty string; CLI flags mapped incorrectly.

Related errors


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