Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/backend/backend/server/v2/store/db.py (Python)

Code before:
            logger.error(
                "Unauthorized update attempt for profile %s by user %s",
                existing_profile.userId,
                user_id,
            )
            raise backend.server.v2.store.exceptions.DatabaseError(
                f"Unauthorized update attempt for profile {existing_profile.id} by user {user_id}"
            )

        logger.debug("Updating existing profile for user %s", user_id)
        # Prepare update data, only including non-None values
        update_data = {}
        if profile.name is not None:
            update_data["name"] = profile.name
        if profile.username is not None:
            update_data["username"] = username
        if profile.description is not None:
            update_data["description"] = profile.description
        if profile.links is not None:
            update_data["links"] = profile.links
        if profile.avatar_url is not None:
            update_data["avatarUrl"] = profile.avatar_url

        # Update the existing profile
        updated_profile = await prisma.models.Profile.prisma().update(
            where={"id": existing_profile.id},
            data=prisma.types.ProfileUpdateInput(**update_data),
        )
        if updated_profile is None:
            logger.error("Failed to update profile for user %s", user_id)
            raise backend.server.v2.store.exceptions.DatabaseError(
                "Failed to update profile"
            )

        return backend.server.v2.store.model.CreatorDetails(
            name=updated_profile.name,
            username=updated_profile.username,
            description=updated_profile.description,
            links=updated_profile.links,
            avatar_url=updated_profile.avatarUrl or "",
            agent_rating=0.0,
            agent_runs=0,
            top_categories=[],
        )

    except prisma.errors.PrismaError as e:
        logger.error("Database error updating profile: %s", str(e))
        raise backend.server.v2.store.exceptions.DatabaseError(
            "Failed to update profile"
        ) from e


Review comment (suggestion):
I this code pass the linter?
You can set `prisma.types.ProfileUpdateInput` as the type of update_data, so you will get the type hint for the code above. e.g: you can avoid setting `update_data` with an invalid key.

Code after:
                "Unauthorized update attempt for profile %s by user %s",
                existing_profile.userId,
                user_id,
            )
            raise backend.server.v2.store.exceptions.DatabaseError(
                f"Unauthorized update attempt for profile {existing_profile.id} by user {user_id}"
            )

        logger.debug("Updating existing profile for user %s", user_id)
        # Prepare update data, only including non-None values
        update_data = {}
        if profile.name is not None:
            update_data["name"] = profile.name
        if profile.username is not None:
            update_data["username"] = username
        if profile.description is not None:
            update_data["description"] = profile.description
        if profile.links is not None:
            update_data["links"] = profile.links
        if profile.avatar_url is not None:
            update_data["avatarUrl"] = profile.avatar_url

        # Update the existing profile
        updated_profile = await prisma.models.Profile.prisma().update(
            where={"id": existing_profile.id},
            data=prisma.types.ProfileUpdateInput(**update_data),
        )
        if updated_profile is None:
            logger.error("Failed to update profile for user %s", user_id)
            raise backend.server.v2.store.exceptions.DatabaseError(
                "Failed to update profile"
            )

        return backend.server.v2.store.model.CreatorDetails(
            name=updated_profile.name,
            username=updated_profile.username,
            description=updated_profile.description,
            links=updated_profile.links,
            avatar_url=updated_profile.avatarUrl or "",
            agent_rating=0.0,
            agent_runs=0,
            top_categories=[],
        )

    except prisma.errors.PrismaError as e:
        logger.error("Database error updating profile: %s", e)
        raise backend.server.v2.store.exceptions.DatabaseError(
            "Failed to update profile"
        ) from e