{"record":{"id":"6b4955c1e81870c5","repo":"Significant-Gravitas/AutoGPT","slug":"failed-to-update-profile","errorCode":null,"errorMessage":"Failed to update profile","messagePattern":"Failed to update profile","errorType":"exception","errorClass":"DatabaseError","httpStatus":500,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/store/db.py","lineNumber":1292,"sourceCode":"        if profile.name is not None:\n            update_data[\"name\"] = profile.name\n        if profile.username is not None:\n            update_data[\"username\"] = username\n        if profile.description is not None:\n            update_data[\"description\"] = profile.description\n        if profile.links is not None:\n            update_data[\"links\"] = profile.links\n        if profile.avatar_url is not None:\n            update_data[\"avatarUrl\"] = profile.avatar_url\n\n        # Update the existing profile\n        updated_profile = await prisma.models.Profile.prisma().update(\n            where={\"id\": existing_profile.id},\n            data=prisma.types.ProfileUpdateInput(**update_data),\n        )\n        if updated_profile is None:\n            logger.error(f\"Failed to update profile for user {user_id}\")\n            raise DatabaseError(\"Failed to update profile\")\n\n        return store_model.ProfileDetails.from_db(updated_profile)\n\n    except prisma.errors.PrismaError as e:\n        logger.error(f\"Database error updating profile: {e}\")\n        raise DatabaseError(\"Failed to update profile\") from e\n\n\nasync def get_my_agents(\n    user_id: str,\n    page: int = 1,\n    page_size: int = 20,\n    organization_id: str | None = None,\n    sort_by: store_model.MyAgentsSortBy = store_model.MyAgentsSortBy.MOST_RECENT,\n    search_query: str | None = None,\n) -> store_model.MyUnpublishedAgentsResponse:\n    \"\"\"Get the agents for the authenticated user\"\"\"\n    logger.debug(","sourceCodeStart":1274,"sourceCodeEnd":1310,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/store/db.py#L1274-L1310","documentation":"DatabaseError raised in update_profile when prisma update() on the existing Profile row returns None. In Prisma, update returns None when the where-unique record no longer matches (row deleted between the earlier find_first and this update), or the write is suppressed by the surrounding transaction. This is a TOCTOU-style gap: the existence check passed, then the row vanished.","triggerScenarios":"Two requests: one deletes the Profile (e.g. account cleanup) while another is mid-update; profile deleted by an admin script during a save; transaction aborted by a concurrent conflicting write.","commonSituations":"User saves profile settings in one tab while another flow resets/deletes the profile; cleanup jobs running during profile edits; duplicated form submissions racing each other.","solutions":["Retry idempotently: re-run update_profile, which will take the create path if the row is gone.","If retries fail, check for processes deleting Profile rows concurrently.","Serialize profile mutations in the client (single in-flight save)."],"exampleFix":"# before (caller)\nawait update_profile(user_id, profile)  # single shot\n# after (caller) — upsert semantics tolerate the vanished row\nfor attempt in range(2):\n    try:\n        return await update_profile(user_id, profile)\n    except DatabaseError:\n        if attempt: raise","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from backend.util.exceptions import DatabaseError\n\nfor attempt in range(2):\n    try:\n        return await store_db.update_profile(user_id, profile)\n    except DatabaseError as e:\n        if 'Failed to update profile' == str(e) and attempt == 0:\n            continue  # row vanished mid-flight; retry takes the create path\n        raise","preventionTips":["Make profile saves idempotent — update_profile creates when the row is absent, so a retry heals the race.","Allow only one in-flight profile save in the UI.","Avoid admin jobs that delete Profile rows during user-active hours."],"tags":["database","prisma","profile","race-condition","store"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}