{"record":{"id":"db0a6a958e9d6d98","repo":"mongodb/mongoid","slug":"attempted-to-persist-a-readonly-document-of-class","errorCode":null,"errorMessage":"Attempted to persist a readonly document of class '%{klass}'.","messagePattern":"Attempted to persist a readonly document of class '%(.+?)'\\.","errorType":"exception","errorClass":"Mongoid::Errors::ReadonlyDocument","httpStatus":null,"severity":"error","filePath":"lib/mongoid/persistable.rb","lineNumber":191,"sourceCode":"      post_persist unless result == false\n      errors.clear unless performing_validations?(options)\n      Threaded.add_modified_document(_session, self) if in_transaction?\n      true\n    end\n\n    # Prepare an atomic persistence operation. Yields an empty hash to be sent\n    # to the update.\n    #\n    # @api private\n    #\n    # @example Prepare the atomic operation.\n    #   document.prepare_atomic_operation do |coll, selector, opts|\n    #     ...\n    #   end\n    #\n    # @return [ Object ] The result of the operation.\n    def prepare_atomic_operation\n      raise Errors::ReadonlyDocument.new(self.class) if readonly? && !Mongoid.legacy_readonly\n\n      operations = yield({})\n      persist_or_delay_atomic_operation(operations)\n      self\n    end\n\n    # Process the atomic operations - this handles the common behavior of\n    # iterating through each op, getting the aliased field name, and removing\n    # appropriate dirty changes.\n    #\n    # @api private\n    #\n    # @example Process the atomic operations.\n    #   document.process_atomic_operations(pulls) do |field, value|\n    #     ...\n    #   end\n    #\n    # @param [ Hash ] operations The atomic operations.","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/persistable.rb#L173-L209","documentation":"Error \"Attempted to persist a readonly document of class '%{klass}'.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/persistable.rb:191 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"}