{"record":{"id":"2f73d89e1e2a8a7d","repo":"marmelab/react-admin","slug":"useshowcontroller-fetched-record-s-id-attribute","errorCode":null,"errorMessage":"useShowController: Fetched record's id attribute (${record.id}) must match the requested 'id' (${id})","messagePattern":"useShowController: Fetched record's id attribute \\((.+?)\\) must match the requested 'id' \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/show/useShowController.ts","lineNumber":120,"sourceCode":"        { id, meta },\n        {\n            enabled:\n                (!isPendingAuthenticated && !isPendingCanAccess) ||\n                disableAuthentication,\n            onError: () => {\n                notify('ra.notification.item_doesnt_exist', {\n                    type: 'error',\n                });\n                redirect(redirectOnError, resource, id);\n            },\n            retry: false,\n            ...otherQueryOptions,\n        }\n    );\n\n    // eslint-disable-next-line eqeqeq\n    if (record && record.id && record.id != id) {\n        throw new Error(\n            `useShowController: Fetched record's id attribute (${record.id}) must match the requested 'id' (${id})`\n        );\n    }\n\n    const getResourceLabel = useGetResourceLabel();\n    const recordRepresentation = getRecordRepresentation(record);\n    const defaultTitle = translate(`resources.${resource}.page.show`, {\n        id,\n        record,\n        recordRepresentation:\n            typeof recordRepresentation === 'string'\n                ? recordRepresentation\n                : '',\n        _: translate('ra.page.show', {\n            name: getResourceLabel(resource, 1),\n            id,\n            record,\n            recordRepresentation:","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/show/useShowController.ts#L102-L138","documentation":"After fetching, useShowController verifies that the record returned by the dataProvider actually has the id that was requested. A mismatch means the data layer returned a different record, which would silently show wrong data, so react-admin throws instead.","triggerScenarios":"A custom dataProvider getOne returns a record whose `id` field differs from the requested id (loose != comparison, so string '5' vs number 5 is fine); a buggy/fake dataProvider returning cached or default data; mapping responses so the id ends up under another key.","commonSituations":"Hand-rolled dataProviders that return { data: { ...record } } from a transformed response while losing the id; mocking providers returning a fixed record regardless of id; API responses keyed by uuid but code reads a numeric field; id normalization lost after JSON parsing.","solutions":["Fix the dataProvider getOne so the returned data.id equals the requested id","Ensure the id key is named `id` in the returned record (or map your API key, e.g. _id → id)","Return undefined/throw in the dataProvider when the record is not found instead of returning an arbitrary record"],"exampleFix":"// before\ngetOne: async (resource, params) => ({ data: { title: 'foo' } }) // id lost\n// after\ngetOne: async (resource, params) => {\n  const raw = await api.fetchOne(resource, params.id);\n  return { data: { ...raw, id: raw._id } };\n}","handlingStrategy":"validation","validationCode":"const { data } = await dataProvider.getOne('posts', { id });\nif (data && data.id != id) throw new Error('dataProvider returned wrong record');","typeGuard":"const matchesId = <T extends { id: Identifier }>(r: T, id: Identifier) => r.id != null && r.id == id;","tryCatchPattern":"try { await dataProvider.getOne(r, { id }); } catch (e) { console.error('getOne returned mismatched id', e); }","preventionTips":["Map your API's id key (_id, uuid) to `id` in the dataProvider","Unit-test getOne returns the exact record for each id","Never return a fallback/default record from getOne"],"tags":["react-admin","data-provider","data-integrity"],"backgroundTag":"record-id-mismatch","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}