{"record":{"id":"21826f3999367a1a","repo":"mongodb/mongoid","slug":"attempted-to-persist-a-readonly-document-of-class-21826f","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/updatable.rb","lineNumber":97,"sourceCode":"      end\n\n      # Prepare the update for execution. Validates and runs callbacks, etc.\n      #\n      # @api private\n      #\n      # @example Prepare for update.\n      #   document.prepare_update do\n      #     collection.update(atomic_selector)\n      #   end\n      #\n      # @param [ Hash ] options The options.\n      #\n      # @option options [ true | false ] :touch Whether or not the updated_at\n      #   attribute will be updated with the current time.\n      #\n      # @return [ true | false ] The result of the update.\n      def prepare_update(options = {})\n        raise Errors::ReadonlyDocument.new(self.class) if readonly? && !Mongoid.legacy_readonly\n\n        enforce_immutability_of_id_field!\n        ensure_client_compatibility!\n        return false if performing_validations?(options) &&\n                        invalid?(options[:context] || :update)\n\n        process_flagged_destroys\n        update_children = cascadable_children(:update)\n        process_touch_option(options) do\n          run_all_callbacks_for_update(update_children) do\n            result = yield(self)\n            self.previously_new_record = false\n            post_process_persist(result, options)\n            true\n          end\n        end\n      end\n","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/persistable/updatable.rb#L79-L115","documentation":"Error \"Attempted to persist a readonly document of class '%{klass}'.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/persistable/updatable.rb:97 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"}