invoke-ai/InvokeAI · error · ValueError

User {user_id} not found

Error message

User {user_id} not found

What it means

UserService.update raises ValueError when the given user_id does not exist in the users table; self.get(user_id) returned None before any changes were applied. It is a pre-condition check, not a write failure, and it fires identically for deleted, never-created, or mistyped IDs.

Source

Thrown at invokeai/app/services/users/users_default.py:191

                SELECT {_USER_DTO_COLUMNS}
                FROM users
                WHERE email = ?
                """,
                (email,),
            )
            row = cursor.fetchone()

        if row is None:
            return None

        return _user_dto_from_row(row)

    def update(self, user_id: str, changes: UserUpdateRequest, strict_password_checking: bool = True) -> UserDTO:
        """Update user."""
        # Check if user exists
        user = self.get(user_id)
        if user is None:
            raise ValueError(f"User {user_id} not found")

        self._assert_system_user_protected(
            user_id, is_admin=changes.is_admin, is_active=changes.is_active, password=changes.password
        )

        # Validate password if provided
        if changes.password is not None:
            if strict_password_checking:
                is_valid, error_msg = validate_password_strength(changes.password)
                if not is_valid:
                    raise ValueError(error_msg)
            elif not changes.password:
                raise ValueError("Password cannot be empty")

        # Build update query dynamically based on provided fields
        updates: list[str] = []
        params: list[str | bool | int] = []

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Verify the ID with users.get(user_id) (or get_by_email) before updating; it returns None for missing users.
  2. Re-fetch the current user list (get_many) to obtain a fresh, valid user_id after DB resets or deletions.
  3. Strip/normalize the user_id string; if it came from an API payload, validate it server-side.
  4. If the user should exist, create them first (create/create_admin) before updating.

Example fix

// before
users.update(user_id, UserUpdateRequest(display_name='New Name'))
// after
if users.get(user_id) is None:
    raise LookupError(f'No user {user_id!r}; pick one from users.get_many()')
users.update(user_id, UserUpdateRequest(display_name='New Name'))
Defensive patterns

Strategy: validation

Validate before calling

user = users.get(user_id)
if user is None:
    raise LookupError(f'User {user_id!r} does not exist')
# safe to update now

Try / catch

try:
    users.update(user_id, changes)
except ValueError as e:
    if str(e) == f'User {user_id} not found':
        logger.warning('Skipping update for missing user %s', user_id)
    else:
        raise

Prevention

When it happens

Trigger: Calling UserService.update(user_id, changes) (e.g. UserUpdateRequest changing display_name, password, is_admin, or is_active) with a user_id that is not present in the database - deleted user, typo/whitespace in the ID, or an ID from another database/environment.

Common situations: Tests and admin scripts reusing stale user IDs after a DB reset; clients caching user IDs that were later deleted; passing a UUID-style string from a different InvokeAI installation; trailing whitespace in a copied ID.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/ff5e8bdbd697ff39. Report an issue: GitHub.