{"record":{"id":"ecf2f97cc895e9ad","repo":"jellyfin/jellyfin","slug":"user-with-userid-authinfo-userid-not-found","errorCode":null,"errorMessage":"User with UserId {authInfo.UserId} not found","messagePattern":"User with UserId (.+?) not found","errorType":"exception","errorClass":"ResourceNotFoundException","httpStatus":404,"severity":"error","filePath":"Jellyfin.Server.Implementations/Devices/DeviceManager.cs","lineNumber":254,"sourceCode":"        /// <inheritdoc />\n        public bool CanAccessDevice(User user, string deviceId)\n        {\n            ArgumentNullException.ThrowIfNull(user);\n            ArgumentException.ThrowIfNullOrEmpty(deviceId);\n\n            if (user.HasPermission(PermissionKind.EnableAllDevices) || user.HasPermission(PermissionKind.IsAdministrator))\n            {\n                return true;\n            }\n\n            return user.GetPreference(PreferenceKind.EnabledDevices).Contains(deviceId, StringComparison.OrdinalIgnoreCase)\n                   || !GetCapabilities(deviceId).SupportsPersistentIdentifier;\n        }\n\n        private DeviceInfo ToDeviceInfo(Device authInfo, DeviceOptions? options = null)\n        {\n            var caps = GetCapabilities(authInfo.DeviceId);\n            var user = _userManager.GetUserById(authInfo.UserId) ?? throw new ResourceNotFoundException(\"User with UserId \" + authInfo.UserId + \" not found\");\n\n            return new()\n            {\n                AppName = authInfo.AppName,\n                AppVersion = authInfo.AppVersion,\n                Id = authInfo.DeviceId,\n                LastUserId = authInfo.UserId,\n                LastUserName = user.Username,\n                Name = authInfo.DeviceName,\n                DateLastActivity = authInfo.DateLastActivity,\n                IconUrl = caps.IconUrl,\n                CustomName = options?.CustomName,\n            };\n        }\n\n        private DeviceOptionsDto ToDeviceOptionsDto(DeviceOptions options)\n        {\n            return new()","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/jellyfin/jellyfin/blob/ae8723026d97b6d0f926638803edef338919b794/Jellyfin.Server.Implementations/Devices/DeviceManager.cs#L236-L272","documentation":"DeviceManager.ToDeviceInfo throws ResourceNotFoundException('User with UserId ... not found') when the Device record's UserId no longer resolves to a user via GetUserById. ToDeviceInfo builds a DeviceInfo including the LastUserName, so it must look up the user; a deleted user makes the lookup return null and the coalescing throw fires.","triggerScenarios":"Listing or fetching devices (GET /Devices) where one or more Device entries reference a UserId that was deleted. ToDeviceInfo is called while projecting each device, so a single stale device aborts the listing.","commonSituations":"Users deleted after their devices were registered; database restores that drop users but keep device rows; multi-server device imports carrying foreign user ids.","solutions":["Clean up orphaned device rows whose UserId no longer exists, then retry the device listing.","Re-add or re-map the referenced user, or delete the stale device entries via the admin UI/API before listing.","If maintaining a custom DeviceManager, guard ToDeviceInfo to skip/filter devices whose user is missing."],"exampleFix":"// before\nvar user = _userManager.GetUserById(authInfo.UserId)\n    ?? throw new ResourceNotFoundException(...);\n// after\nvar user = _userManager.GetUserById(authInfo.UserId);\nif (user is null) return null; // filter orphaned devices upstream","handlingStrategy":"validation","validationCode":"// Before listing devices, prune orphans\nvar users = (await client.GetUsersAsync()).Select(u => u.Id).ToHashSet();\nvar devices = (await client.GetDevicesAsync()).Where(d => users.Contains(d.UserId));","typeGuard":"bool UserExists(Guid id, HashSet<Guid> known) => known.Contains(id);","tryCatchPattern":"try { devices = await client.GetDevicesAsync(); }\ncatch (ResourceNotFoundException e) when (e.Message.Contains(\"User with UserId\"))\n{ await CleanupOrphanedDevices(); devices = await client.GetDevicesAsync(); }","preventionTips":["When deleting a user, also remove their device records.","Audit device rows for stale UserIds after DB restores.","In custom DeviceManagers, filter out devices whose user is missing."],"tags":["user-management","devices","resource-not-found","data-integrity"],"backgroundTag":null,"analyzedSha":"ae8723026d97b6d0f926638803edef338919b794","analyzedAt":"2026-08-13T10:43:30.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}