{"record":{"id":"fd65e5888a1706d5","repo":"remix-run/remix","slug":"create-returnrow-true-failed-to-return-an-in","errorCode":null,"errorMessage":"create({ returnRow: true }) failed to return an inserted row","messagePattern":"create\\((.+?)\\) failed to return an inserted row","errorType":"exception","errorClass":"DataTableQueryError","httpStatus":null,"severity":"error","filePath":"packages/data-table/src/lib/database.ts","lineNumber":580,"sourceCode":"    options?: CreateResultOptions | CreateRowOptions<table, relations>,\n  ): Promise<WriteResult | TableRowWith<table, LoadedRelationMap<relations>>> {\n    let touch = options?.touch\n    let query: QueryForTable<table> = this.query(asQueryTableInput(table))\n\n    if (options?.returnRow !== true) {\n      let result = await query.insert(values, { touch })\n      return toWriteResult(result)\n    }\n\n    if (this.capabilities.returning) {\n      let result = (await query.insert(values, {\n        returning: '*',\n        touch,\n      })) as { row: TableRow<table> | null }\n      let row = result.row\n\n      if (!row) {\n        throw new DataTableQueryError(\n          'create({ returnRow: true }) failed to return an inserted row',\n        )\n      }\n\n      if (!options.with) {\n        return row as TableRowWith<table, LoadedRelationMap<relations>>\n      }\n\n      let where = getPrimaryKeyWhereFromRow(table, row)\n      let loaded = await this.findOne(table, {\n        where,\n        with: options.with,\n      })\n\n      if (!loaded) {\n        throw new DataTableQueryError('create({ returnRow: true }) failed to load inserted row')\n      }\n","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/data-table/src/lib/database.ts#L562-L598","documentation":"When create() is called with returnRow: true and the database supports RETURNING, it executes the insert with returning: '*' and expects a row back. If the driver returns no row (result.row is null/undefined), this error is thrown, indicating the insert succeeded as a statement but the driver/compiler failed to return the inserted data — a driver contract violation rather than a caller mistake.","triggerScenarios":"db.create(table, values, { returnRow: true }) on a database advertising capabilities.returning where the RETURNING clause is dropped or the driver mis-parses the returned row; custom drivers that resolve inserts without echoing rows.","commonSituations":"Writing/testing a custom driver that forgets to map RETURNING results; SQLite wrappers where lastInsertRowid is used but the row fetch fails; version skew between driver and core.","solutions":["If you maintain the driver, ensure inserts with returning: '*' resolve with { row } populated from the RETURNING result.","If using a built-in driver, update data-table and driver packages to matching versions — this indicates a driver bug.","As a workaround, drop returnRow and re-fetch the row yourself via findOne using the primary key."],"exampleFix":"// before\nlet row = await db.create(users, values, { returnRow: true })\n\n// after\nlet result = await db.create(users, values)\nlet row = await db.findOne(users, eq(users.id, result.primaryKey))","handlingStrategy":"fallback","validationCode":"if (db.capabilities.returning) {\n  row = await db.create(table, values, { returnRow: true })\n} else {\n  await db.create(table, values)\n  row = await db.findOne(table, where)\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await db.create(t, v, { returnRow: true })\n} catch (error) {\n  if (error instanceof DataTableQueryError && /failed to return/.test(error.message)) {\n    return await db.findOne(t, where) // manual fallback\n  }\n  throw error\n}","preventionTips":["Check db.capabilities.returning before requesting rows back.","Report driver bugs upstream with the failing operation."],"tags":["data-table","insert","returning","driver"],"backgroundTag":"driver-returning-contract","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}