{"record":{"id":"779cf68c2bd85468","repo":"mongodb/mongoid","slug":"transaction-failed-with-the-following-error-err","errorCode":null,"errorMessage":"Transaction failed with the following error: %{error}.","messagePattern":"Transaction failed with the following error: %(.+?)\\.","errorType":"exception","errorClass":"Mongoid::Errors::TransactionError","httpStatus":null,"severity":"error","filePath":"lib/mongoid/clients/sessions.rb","lineNumber":95,"sourceCode":"        # @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)\n        end\n\n        # Shortcut for +after_commit :hook, on: [ :create, :update ]+","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/clients/sessions.rb#L77-L113","documentation":"Error \"Transaction failed with the following error: %{error}.\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/clients/sessions.rb:95 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"}