Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"PDOException: There is no active transaction" when creating a tenant (PHP 8). #1033

Open
logan-waite opened this issue Dec 21, 2022 · 0 comments

Comments

@logan-waite
Copy link

logan-waite commented Dec 21, 2022

I'm currently working on upgrading my laravel app to run on PHP 8, and I got this error when trying to seed my local DB with some default tenants:

 PDOException 

  There is no active transaction

  at vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:45
     41▕             }
     42▕ 
     43▕             try {
     44▕                 if ($this->transactions == 1) {
  ➜  45▕                     $this->getPdo()->commit();
     46▕                 }
     47▕ 
     48▕                 $this->transactions = max(0, $this->transactions - 1);
     49▕ 

      +34 vendor frames 
  35  app/Console/Commands/TenantCreate.php:63
      Hyn\Tenancy\Repositories\WebsiteRepository::create()

      +15 vendor frames 
  51  database/seeds/TenantSeeder.php:33
      Illuminate\Support\Facades\Facade::__callStatic()

My command handle function hasn't changed since before the upgrade, and still seems to match what is in the documentation:

        $fqdn = $this->argument('fqdn');
        $hostname = new Hostname;
        $hostname->fqdn = $fqdn;
        $hostname = app(HostnameRepository::class)->create($hostname);

        $website = new Website;
        app(WebsiteRepository::class)->create($website);

        app(HostnameRepository::class)->attach($hostname, $website);
        $tenant->save();

Here is the stack trace Laravel prints for me:

[2022-12-21 15:52:44] local.ERROR: There is no active transaction {"exception":"[object] (PDOException(code: 0): There is no active transaction at /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:45)
[stacktrace]
#0 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php(45): PDO->commit()
#1 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(402): Illuminate\\Database\\Connection->transaction()
#2 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(202): Illuminate\\Database\\Migrations\\Migrator->runMigration()
#3 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(167): Illuminate\\Database\\Migrations\\Migrator->runUp()
#4 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(112): Illuminate\\Database\\Migrations\\Migrator->runPending()
#5 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(86): Illuminate\\Database\\Migrations\\Migrator->run()
#6 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(606): Illuminate\\Database\\Console\\Migrations\\MigrateCommand->Illuminate\\Database\\Console\\Migrations\\{closure}()
#7 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php(98): Illuminate\\Database\\Migrations\\Migrator->usingConnection()
#8 /home/vagrant/code/bridge/portal/vendor/hyn/multi-tenant/src/Traits/AddWebsiteFilterOnCommand.php(34): Illuminate\\Database\\Console\\Migrations\\MigrateCommand->handle()
#9 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(245): Hyn\\Tenancy\\Database\\Console\\Migrations\\MigrateCommand->Hyn\\Tenancy\\Traits\\{closure}()
#10 /home/vagrant/code/bridge/portal/vendor/hyn/multi-tenant/src/Traits/AddWebsiteFilterOnCommand.php(39): Illuminate\\Support\\Collection->each()
#11 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(51): Hyn\\Tenancy\\Database\\Console\\Migrations\\MigrateCommand->Hyn\\Tenancy\\Traits\\{closure}()
#12 /home/vagrant/code/bridge/portal/vendor/hyn/multi-tenant/src/Traits/AddWebsiteFilterOnCommand.php(40): Illuminate\\Database\\Eloquent\\Builder->chunk()
#13 /home/vagrant/code/bridge/portal/vendor/hyn/multi-tenant/src/Traits/MutatesMigrationCommands.php(55): Hyn\\Tenancy\\Database\\Console\\Migrations\\MigrateCommand->processHandle()
#14 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Hyn\\Tenancy\\Database\\Console\\Migrations\\MigrateCommand->handle()
#15 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#16 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#17 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#18 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\\Container\\BoundMethod::call()
#19 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call()
#20 /home/vagrant/code/bridge/portal/vendor/symfony/console/Command/Command.php(298): Illuminate\\Console\\Command->execute()
#21 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run()
#22 /home/vagrant/code/bridge/portal/vendor/symfony/console/Application.php(1040): Illuminate\\Console\\Command->run()
#23 /home/vagrant/code/bridge/portal/vendor/symfony/console/Application.php(301): Symfony\\Component\\Console\\Application->doRunCommand()
#24 /home/vagrant/code/bridge/portal/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun()
#25 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\\Component\\Console\\Application->run()
#26 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Application.php(186): Illuminate\\Console\\Application->run()
#27 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(263): Illuminate\\Console\\Application->call()
#28 /home/vagrant/code/bridge/portal/vendor/hyn/multi-tenant/src/Database/Connection.php(266): Illuminate\\Foundation\\Console\\Kernel->call()
#29 /home/vagrant/code/bridge/portal/vendor/hyn/multi-tenant/src/Listeners/Database/MigratesTenants.php(55): Hyn\\Tenancy\\Database\\Connection->migrate()
#30 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(404): Hyn\\Tenancy\\Listeners\\Database\\MigratesTenants->migrate()
#31 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(249): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}()
#32 /home/vagrant/code/bridge/portal/vendor/hyn/multi-tenant/src/Traits/DispatchesEvents.php(29): Illuminate\\Events\\Dispatcher->dispatch()
#33 /home/vagrant/code/bridge/portal/vendor/hyn/multi-tenant/src/Repositories/WebsiteRepository.php(97): Hyn\\Tenancy\\Repositories\\WebsiteRepository->emitEvent()
#34 /home/vagrant/code/bridge/portal/app/Console/Commands/TenantCreate.php(63): Hyn\\Tenancy\\Repositories\\WebsiteRepository->create()
#35 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\\Console\\Commands\\TenantCreate->handle()
#36 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#37 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#38 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#39 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\\Container\\BoundMethod::call()
#40 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call()
#41 /home/vagrant/code/bridge/portal/vendor/symfony/console/Command/Command.php(298): Illuminate\\Console\\Command->execute()
#42 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run()
#43 /home/vagrant/code/bridge/portal/vendor/symfony/console/Application.php(1040): Illuminate\\Console\\Command->run()
#44 /home/vagrant/code/bridge/portal/vendor/symfony/console/Application.php(301): Symfony\\Component\\Console\\Application->doRunCommand()
#45 /home/vagrant/code/bridge/portal/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun()
#46 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\\Component\\Console\\Application->run()
#47 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Application.php(186): Illuminate\\Console\\Application->run()
#48 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(263): Illuminate\\Console\\Application->call()
#49 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\\Foundation\\Console\\Kernel->call()
#50 /home/vagrant/code/bridge/portal/database/seeds/TenantSeeder.php(33): Illuminate\\Support\\Facades\\Facade::__callStatic()
#51 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): TenantSeeder->run()
#52 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#53 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#54 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#55 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\\Container\\BoundMethod::call()
#56 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(149): Illuminate\\Container\\Container->call()
#57 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(49): Illuminate\\Database\\Seeder->__invoke()
#58 /home/vagrant/code/bridge/portal/database/seeds/DatabaseSeeder.php(16): Illuminate\\Database\\Seeder->call()
#59 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): DatabaseSeeder->run()
#60 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#61 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#62 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#63 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\\Container\\BoundMethod::call()
#64 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(149): Illuminate\\Container\\Container->call()
#65 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(66): Illuminate\\Database\\Seeder->__invoke()
#66 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php(157): Illuminate\\Database\\Console\\Seeds\\SeedCommand->Illuminate\\Database\\Console\\Seeds\\{closure}()
#67 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(67): Illuminate\\Database\\Eloquent\\Model::unguarded()
#68 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Database\\Console\\Seeds\\SeedCommand->handle()
#69 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#70 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#71 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#72 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\\Container\\BoundMethod::call()
#73 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call()
#74 /home/vagrant/code/bridge/portal/vendor/symfony/console/Command/Command.php(298): Illuminate\\Console\\Command->execute()
#75 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run()
#76 /home/vagrant/code/bridge/portal/vendor/symfony/console/Application.php(1040): Illuminate\\Console\\Command->run()
#77 /home/vagrant/code/bridge/portal/vendor/symfony/console/Application.php(301): Symfony\\Component\\Console\\Application->doRunCommand()
#78 /home/vagrant/code/bridge/portal/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun()
#79 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\\Component\\Console\\Application->run()
#80 /home/vagrant/code/bridge/portal/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run()
#81 /home/vagrant/code/bridge/portal/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle()
#82 {main}
"} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant