laravel-mongodb - Issue #3328: Incorrect behavior of the transaction method

XMLWordPrintableJSON

    • 🔵 Done
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      babaduk47 has created Issue #3328: Incorrect behavior of the transaction method in laravel-mongodb. This Jira ticket was filed by GromNaN

      Issue Text:

      • Laravel-mongodb Version: 5.2.0
      • PHP Version: 8.3.17
      • Database Driver & Version: 1.21.1

      Description:

      The transaction method of the mongodb connection does not call the beginTransaction method. If dispatch job with afterCommit=true, the queue will be sent before commit. This behavior differs from mysql connection

      Steps to reproduce

      try {
          DB::connection('mysql')->transaction(static function (): void {
              dispatch(fn() => dump('dump from mysql dispatch'))
                  ->onConnection('sync')
                  ->afterCommit();
      
              throw new \Exception('Command not executed.');
          });
      } catch (\Exception) {
      }
      
      try {
          DB::connection('mongodb')->transaction(static function (): void {
              dispatch(fn() => dump('dump from mongodb dispatch'))
                  ->onConnection('sync')
                  ->afterCommit();
      
              throw new \Exception('Command not executed.');
          });
      } catch (\Exception) {
      }
      

      Expected behaviour

      Jobs will not be completed

      Actual behaviour

      We get dump = `dump from mongodb dispatch`

      Additional debug

      DB::connection('mysql')->transaction(static function (): void {
          $connection = DB::connection('mysql');
      
          $transactionsManager = (fn () => $this->transactionsManager)->bindTo($connection, $connection)();
          $pendingTransactions = (fn () => $this->pendingTransactions->all())->bindTo($transactionsManager, $transactionsManager)();
      
          dump('mysql transactionLevel: ' . DB::connection('mysql')->transactionLevel());
          dump('mysql pendingTransactions: ', $pendingTransactions);
      });
      
      DB::connection('mongodb')->transaction(static function (): void {
          $connection = DB::connection('mongodb');
      
          $transactionsManager = (fn () => $this->transactionsManager)->bindTo($connection, $connection)();
          $pendingTransactions = (fn () => $this->pendingTransactions->all())->bindTo($transactionsManager, $transactionsManager)();
      
          dump('mongodb transactionLevel: ' . DB::connection('mongodb')->transactionLevel());
          dump('mongodb pendingTransactions: ', $pendingTransactions);
      });
      

      <img width="741" alt="Image" src="https://github.com/user-attachments/assets/e0ce298c-2092-4318-ac06-e25ab4508ff2" />

            Assignee:
            Pauline Vos
            Reporter:
            TPM Jira Automations Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: