{"record":{"id":"9c335d51f409ee3d","repo":"hashicorp/vault","slug":"a-record-already-exists-with-the-name-name","errorCode":null,"errorMessage":"A record already exists with the name: ${name}","messagePattern":"A record already exists with the name: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"ui/app/adapters/named-path.js","lineNumber":34,"sourceCode":"  _saveRecord(store, { modelName }, snapshot) {\n    // since the response is empty return the serialized data rather than nothing\n    const data = store.serializerFor(modelName).serialize(snapshot);\n    const primaryKey = store.serializerFor(modelName).primaryKey;\n    return this.ajax(this.urlForUpdateRecord(snapshot.attr('name'), modelName, snapshot), this.saveMethod, {\n      data,\n    }).then(() => {\n      data[primaryKey] = snapshot.attr(primaryKey);\n      return data;\n    });\n  }\n\n  // create does not return response similar to PUT request\n  createRecord() {\n    const [store, { modelName }, snapshot] = arguments;\n    const name = snapshot.attr('name');\n    // throw error if user attempts to create a record with same name, otherwise POST request silently overrides (updates) the existing model\n    if (store.peekRecord({ type: modelName, id: name }) !== null) {\n      throw new Error(`A record already exists with the name: ${name}`);\n    } else {\n      return this._saveRecord(...arguments);\n    }\n  }\n\n  // update uses same endpoint and method as create\n  updateRecord() {\n    return this._saveRecord(...arguments);\n  }\n\n  // if backend does not return name in response Ember Data will throw an error for pushing a record with no id\n  // use the id (name) supplied to findRecord to set property on response data\n  findRecord(store, type, name) {\n    return super.findRecord(...arguments).then((resp) => {\n      if (!resp.data.name) {\n        resp.data.name = name;\n      }\n      return resp;","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/hashicorp/vault/blob/744b611b5700b3b7f82d76b4d6938a91b9989367/ui/app/adapters/named-path.js#L16-L52","documentation":"Thrown by the named-path adapter (ui/app/adapters/named-path.js:34) used for Vault resources whose ID is a user-chosen name. The Vault HTTP API upserts on POST for these endpoints, so creating a record with an existing name would silently overwrite it. The adapter guards against this by peeking the Ember store for the name before delegating to _saveRecord().","triggerScenarios":"store.createRecord(...).save() (POST /v1/<named-path>) when store.peekRecord({type: modelName, id: name}) already finds a record with the same name in the local store cache — typically because the item is visible in the current list or was loaded earlier in the session.","commonSituations":"User submits a create form with a name that is already in the list (duplicate tab, stale list after another admin added the same name); tests that do not reset the Ember store between runs; the browser back button resubmitting a create form.","solutions":["Choose a different, unique name for the new record","Reload the parent list so the store cache reflects what actually exists, then retry","If you meant to modify the existing item, edit it instead of creating a new one"],"exampleFix":"// before\nconst record = this.store.createRecord('pki/role', { name });\nawait record.save();\n\n// after\nif (this.store.peekRecord('pki/role', name)) {\n  this.flash.warning(`\"${name}\" already exists — edit it instead of creating a new one.`);\n} else {\n  const record = this.store.createRecord('pki/role', { name });\n  await record.save();\n}","handlingStrategy":"validation","validationCode":"// Check for the name before creating — mirror the adapter's own guard at the caller\nconst existing = store.peekRecord(modelName, name);\nif (existing) {\n  // route the user to edit instead of silently overwriting via POST\n  this.router.transitionTo('edit-route', existing);\n} else {\n  await this._saveRecord(...);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await record.save();\n} catch (e) {\n  if (e.message.startsWith('A record already exists with the name:')) {\n    notifyUser('Name taken — edit the existing record or pick another name');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Refresh the listing right before showing a create form so peekRecord sees current data","Remember the guard only checks the local Ember store — a name created by someone else can still silently upsert server-side, so list before create when collisions matter","In tests, fully reset the store between cases or this guard will fire from leftover fixtures"],"tags":["ember-data","adapter","validation","duplicate","named-path"],"backgroundTag":null,"analyzedSha":"744b611b5700b3b7f82d76b4d6938a91b9989367","analyzedAt":"2026-08-15T14:40:29.333Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}