{"record":{"id":"7132309a67a02388","repo":"puppetlabs/puppet","slug":"instance-name-name-does-not-match-requested-key","errorCode":null,"errorMessage":"Instance name %{name} does not match requested key %{key}","messagePattern":"Instance name %(.+?) does not match requested key %(.+?)","errorType":"validation","errorClass":"Puppet::Indirector::ValidationError","httpStatus":null,"severity":"error","filePath":"lib/puppet/indirector/terminus.rb","lineNumber":171,"sourceCode":"\n  def allow_remote_requests?\n    true\n  end\n\n  def terminus_type\n    self.class.terminus_type\n  end\n\n  def validate(request)\n    if request.instance\n      validate_model(request)\n      validate_key(request)\n    end\n  end\n\n  def validate_key(request)\n    unless request.key == request.instance.name\n      raise Puppet::Indirector::ValidationError, _(\"Instance name %{name} does not match requested key %{key}\") % { name: request.instance.name.inspect, key: request.key.inspect }\n    end\n  end\n\n  def validate_model(request)\n    unless model === request.instance\n      raise Puppet::Indirector::ValidationError, _(\"Invalid instance type %{klass}, expected %{model_type}\") % { klass: request.instance.class.inspect, model_type: model.inspect }\n    end\n  end\nend\n","sourceCodeStart":153,"sourceCodeEnd":181,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/indirector/terminus.rb#L153-L181","documentation":"The base Terminus#validate_key requires that when a request carries an instance, request.key equals instance.name exactly (both are inspected in the message). It runs during Terminus#validate on write-path operations (save/head) for termini that validate requests, catching the case where a caller names an object differently from the key under which it is being stored — e.g., saving a node whose .name is 'web01' under key 'web01.example.com'.","triggerScenarios":"Calling indirection.save(instance, key) or constructing a request whose key differs from instance.name: Puppet::Node.indirection.save(node, node.name + '.example.com'), or deserialized instances whose name was mutated after the request key was computed.","commonSituations":"Tooling that stores objects under FQDN keys while the object's name is the short hostname (or vice versa); normalize-name functions applied to one side but not the other; test fixtures hard-coding keys that drift from fixture data.","solutions":["Always pass the instance's own name as the key: indirection.save(instance, instance.name)","If a different storage key is required, set instance.name to that value before saving","Search the code path for any mutation of .name after request creation and move it before the request is built","Compare the two inspected values in the error message to spot whitespace/case drift quickly"],"exampleFix":"# before\nfacts = Puppet::Node::Facts.new('web01', values)\nPuppet::Node::Facts.indirection.save(facts, 'web01.example.com')\n# => Instance name \"web01\" does not match requested key \"web01.example.com\"\n\n# after\nfacts = Puppet::Node::Facts.new('web01.example.com', values)\nPuppet::Node::Facts.indirection.save(facts, 'web01.example.com')","handlingStrategy":"validation","validationCode":"if request.instance && request.instance.respond_to?(:name) && request.key != request.instance.name\n  raise Puppet::Indirector::ValidationError, \"key #{request.key.inspect} != name #{request.instance.name.inspect}\"\nend","typeGuard":"def name_matches_key?(instance, key)\n  instance.respond_to?(:name) && instance.name == key\nend","tryCatchPattern":null,"preventionTips":["Always call indirection.save(instance, instance.name)","Apply any hostname normalization (fqdn vs short) before both name assignment and key creation","Assert key/name equality in shared factory helpers used by tests"],"tags":["puppet","indirector","validation","key-mismatch","save"],"backgroundTag":"request-key-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}