{"record":{"id":"b63ad1a2e4496d9c","repo":"mongodb/mongoid","slug":"attempted-to-change-the-immutable-attribute-nam","errorCode":null,"errorMessage":"Attempted to change the immutable attribute '%{name}' with the value: %{value}.","messagePattern":"Attempted to change the immutable attribute '%(.+?)' with the value: %(.+?)\\.","errorType":"exception","errorClass":"Mongoid::Errors::ImmutableAttribute","httpStatus":null,"severity":"error","filePath":"lib/mongoid/association/nested/one.rb","lineNumber":165,"sourceCode":"        # immutable) is being asked to change. If so, raise an exception.\n        #\n        # If Mongoid::Config.immutable_ids is false, this will do nothing,\n        # and the update operation will fail silently.\n        #\n        # @raise [ Errors::ImmutableAttribute ] if _id has changed, and\n        #   the document has been persisted.\n        def check_for_id_violation!\n          # look for the basic criteria of an update (see #update?)\n          return unless existing&.persisted? && !destroyable?\n\n          # if the id is either absent, or if it equals the existing record's\n          # id, there is no immutability violation.\n          id = extracted_id\n          return if existing._id == id || id.nil?\n\n          # otherwise, an attempt has been made to set the _id of an existing,\n          # persisted document.\n          raise Errors::ImmutableAttribute.new(:_id, id) if Mongoid::Config.immutable_ids\n\n          Mongoid::Warnings.warn_mutable_ids\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":147,"sourceCodeEnd":173,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/association/nested/one.rb#L147-L173","documentation":"Error \"Attempted to change the immutable attribute '%{name}' with the value: %{value}.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/association/nested/one.rb:165 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}