{"record":{"id":"6e9e9c1a273fb026","repo":"mongodb/mongoid","slug":"sessions-not-supported","errorCode":null,"errorMessage":"sessions_not_supported","messagePattern":"sessions_not_supported","errorType":"exception","errorClass":"Mongoid::Errors::SessionsNotSupported","httpStatus":null,"severity":"error","filePath":"lib/mongoid/clients/sessions.rb","lineNumber":45,"sourceCode":"        #   end\n        #\n        # @param [ Hash ] options The session options. Please see the driver\n        #   documentation for the available session options.\n        #\n        # @raise [ Errors::InvalidSessionUse ] If an operation is attempted on a model using another\n        #   client from which the session was started or if sessions are nested.\n        #\n        # @return [ Object ] The result of calling the block.\n        #\n        # @yieldparam [ Mongo::Session ] The session being used for the block.\n        def with_session(options = {})\n          raise Mongoid::Errors::InvalidSessionNesting.new if Threaded.get_session(client: persistence_context.client)\n\n          session = persistence_context.client.start_session(options)\n          Threaded.set_session(session, client: persistence_context.client)\n          yield(session)\n        rescue Mongo::Error::InvalidSession => e\n          raise Mongoid::Errors::SessionsNotSupported.new if e.is_a?(Mongo::Error::SessionsNotSupported)\n\n          raise e\n        rescue Mongo::Error::OperationFailure => e\n          if (e.code == 40_415 && e.server_message =~ /startTransaction/) ||\n             (e.code == 20 && e.server_message =~ /Transaction/)\n            raise Mongoid::Errors::TransactionsNotSupported.new\n          else\n            raise e\n          end\n        rescue *transactions_not_supported_exceptions\n          raise Mongoid::Errors::TransactionsNotSupported\n        ensure\n          Threaded.clear_modified_documents(session)\n          Threaded.clear_session(client: persistence_context.client)\n        end\n\n        # Executes a block within the context of a transaction.\n        #","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/clients/sessions.rb#L27-L63","documentation":"Error \"sessions_not_supported\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/clients/sessions.rb:45 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"}