{"record":{"id":"1bbcf946a5446500","repo":"mongodb/mongoid","slug":"a-transaction-was-started-while-another-transactio","errorCode":null,"errorMessage":"A transaction was started while another transaction was being used on this client.","messagePattern":"A transaction was started while another transaction was being used on this client\\.","errorType":"exception","errorClass":"Mongoid::Errors::InvalidTransactionNesting","httpStatus":null,"severity":"error","filePath":"lib/mongoid/clients/sessions.rb","lineNumber":92,"sourceCode":"        #\n        # @raise [ Mongoid::Errors::InvalidTransactionNesting ] If the transaction is\n        #   opened on a client that already has an open transaction.\n        # @raise [ Mongoid::Errors::TransactionsNotSupported ] If MongoDB deployment\n        #   the client is connected to does not support transactions.\n        # @raise [ Mongoid::Errors::TransactionError ] If there is an error raised\n        #   by MongoDB deployment or MongoDB driver.\n        #\n        # @yield Provided block will be executed inside a transaction.\n        def transaction(options = {}, session_options: {}, &block)\n          with_session(session_options) do |session|\n            session.with_transaction(options, &block).tap { run_commit_callbacks(session) }\n          rescue *transactions_not_supported_exceptions\n            raise Mongoid::Errors::TransactionsNotSupported\n          rescue Mongoid::Errors::Rollback\n            run_abort_callbacks(session)\n          rescue Mongoid::Errors::InvalidSessionNesting\n            # Session should be ended here.\n            raise Mongoid::Errors::InvalidTransactionNesting.new\n          rescue Mongo::Error::InvalidSession, Mongo::Error::InvalidTransactionOperation => e\n            run_abort_callbacks(session)\n            raise Mongoid::Errors::TransactionError.new(e)\n          rescue StandardError => e\n            run_abort_callbacks(session)\n            raise e\n          end\n        end\n\n        # Sets up a callback is called after a commit of a transaction.\n        # The callback is called only if the document is created, updated, or destroyed\n        # in the transaction.\n        #\n        # See +ActiveSupport::Callbacks::ClassMethods::set_callback+ for more\n        # information about method parameters and possible options.\n        def after_commit(*args, &block)\n          set_options_for_callbacks!(args)\n          set_callback(:commit, :after, *args, &block)","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/clients/sessions.rb#L74-L110","documentation":"Error \"A transaction was started while another transaction was being used on this client.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/clients/sessions.rb:92 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"}