{"record":{"id":"d6af209330af6b5d","repo":"puppetlabs/puppet","slug":"the-attribute-name-is-reserved-and-cannot-be","errorCode":null,"errorMessage":"The attribute '%{name}' is reserved and cannot be used","messagePattern":"The attribute '%(.+?)' is reserved and cannot be used","errorType":"exception","errorClass":"Puppet::ParseError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_object_type.rb","lineNumber":299,"sourceCode":"  end\n\n  # Describes a named Attribute in an Object type\n  # @api public\n  class PAttribute < PAnnotatedMember\n    # @return [String,nil] The attribute kind as defined by #TYPE_ATTRIBUTE_KIND, or `nil`\n    attr_reader :kind\n\n    # @param name [String] The name of the attribute\n    # @param container [PObjectType] The containing object type\n    # @param init_hash [Hash{String=>Object}] Hash containing attribute options\n    # @option init_hash [PAnyType] 'type' The attribute type (required)\n    # @option init_hash [Object] 'value' The default value, must be an instanceof the given `type` (optional)\n    # @option init_hash [String] 'kind' The attribute kind, matching #TYPE_ATTRIBUTE_KIND\n    # @api public\n    def initialize(name, container, init_hash)\n      super(name, container, TypeAsserter.assert_instance_of(nil, TYPE_ATTRIBUTE, init_hash) { \"initializer for #{self.class.label(container, name)}\" })\n      if name == Serialization::PCORE_TYPE_KEY || name == Serialization::PCORE_VALUE_KEY\n        raise Puppet::ParseError, _(\"The attribute '%{name}' is reserved and cannot be used\") % { name: name }\n      end\n\n      @kind = init_hash[KEY_KIND]\n      if @kind == ATTRIBUTE_KIND_CONSTANT # final is implied\n        if init_hash.include?(KEY_FINAL) && !@final\n          # TRANSLATOR 'final => false' is puppet syntax and should not be translated\n          raise Puppet::ParseError, _(\"%{label} of kind 'constant' cannot be combined with final => false\") % { label: label }\n        end\n\n        @final = true\n      end\n\n      if init_hash.include?(KEY_VALUE)\n        if @kind == ATTRIBUTE_KIND_DERIVED || @kind == ATTRIBUTE_KIND_GIVEN_OR_DERIVED\n          raise Puppet::ParseError, _(\"%{label} of kind '%{kind}' cannot be combined with an attribute value\") % { label: label, kind: @kind }\n        end\n\n        v = init_hash[KEY_VALUE]","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_object_type.rb#L281-L317","documentation":"The keys '__ptype' and '__pvalue' (Serialization::PCORE_TYPE_KEY and PCORE_VALUE_KEY) carry the type tag and payload in Puppet's serialized PCore format, so an Object type attribute may not use either name — allowing it would make serialized output ambiguous. PAttribute#initialize raises this Puppet::ParseError immediately.","triggerScenarios":"An Object type declaration with attributes => {'__ptype' => ...} or {'__pvalue' => ...}, typically when attribute names are generated mechanically from external data (JSON schemas, DB columns, message field names) that happen to contain those keys.","commonSituations":"Codegen that derives Puppet Object types from external schemas without filtering reserved names; round-tripping serialized PCore hashes back into type definitions.","solutions":["Rename the attribute to anything else (e.g. 'pcore_type' / 'pvalue_').","If names come from external data, filter reserved keys ('__ptype', '__pvalue') during generation with an allowlist/prefix strategy.","Keep serialization metadata out of your domain attributes; model only real data fields."],"exampleFix":"# before\ntype Rec = Object[{'attributes' => {'__ptype' => String}}]\n\n# after\ntype Rec = Object[{'attributes' => {'pcore_type_name' => String}}]","handlingStrategy":"validation","validationCode":"# Ruby — filter reserved keys when generating attribute names\nRESERVED = [Puppet::Pops::Serialization::PCORE_TYPE_KEY, Puppet::Pops::Serialization::PCORE_VALUE_KEY].freeze\nfail(\"attribute name #{n} is reserved\") if RESERVED.include?(n)","typeGuard":"def usable_attribute_name?(name)\n  name != '__ptype' && name != '__pvalue'\nend","tryCatchPattern":null,"preventionTips":["Namespace generated attribute names (prefix them) when they originate from external schemas.","Know the two reserved keys __ptype/__pvalue — they belong to PCore serialization only."],"tags":["puppet","object-type","reserved-names","serialization","pcore"],"backgroundTag":"reserved-field-name-collision","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}