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

BUG on transaction (PDOException: There is no active transaction) #370

Open
1 of 3 tasks
ludeus opened this issue Sep 26, 2018 · 2 comments
Open
1 of 3 tasks

BUG on transaction (PDOException: There is no active transaction) #370

ludeus opened this issue Sep 26, 2018 · 2 comments
Labels
Milestone

Comments

@ludeus
Copy link

ludeus commented Sep 26, 2018

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.6.11

  • Migrations plugin version: 2.0.0

  • Database server: Postgres 9.5.13

  • PHP Version: 7.2.9

  • Platform / OS: Ubuntu 16.04 LTS

What you did

Insert data in the up() function.
Here a small example:

<?php

use Cake\ORM\TableRegistry;
use Migrations\AbstractMigration;

class CreateTest extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('tests');
        $table->addColumn('name', 'string', [
            'default' => null,
            'limit' => 255,
            'null' => false,
        ]);
        $table->create();

        $table = TableRegistry::getTableLocator()->get('Tests');
        $entity = $table->newEntity(['name' => 'foo']);
        $table->save($entity);
    }
    public function down()
    {
        $this->table('tests')->drop()->save();
    }
}

Note: this code work in migrations v1.7.2

Expected Behavior

Creation of table: tests and insertion of 'foo'

Actual Behavior

Exception: There is no active transaction in [/.../vendor/cakephp/cakephp/src/Database/Driver.php, line 197]

Alternatives

This work:

$table->save($entity, ['atomic' => false]);

But this wont:

$table = TableRegistry::getTableLocator()->get('Tests');
$table->addBehavior('Acl.Acl', ['type' => 'requester']);
$entity = $table->newEntity(['name' => 'foo']);
$table->save($entity, ['atomic' => false]);

This work:

$this->getAdapter()->commitTransaction();
$table = TableRegistry::getTableLocator()->get('Tests');
$table->addBehavior('Acl.Acl', ['type' => 'requester']);
$entity = $table->newEntity(['name' => 'foo']);
$table->save($entity, ['atomic' => false]);
$this->getAdapter()->beginTransaction();

The full working example file:
20180926072527_CreateTest.php.txt

@ravage84 ravage84 added this to the 1.7.2 milestone Sep 27, 2018
@ravage84 ravage84 added the bug label Sep 27, 2018
@rchavik
Copy link
Member

rchavik commented Aug 23, 2019

I had similar issue when using the seed feature for postgresql. Using your workaround works. So thanks!

But I thought this was fixed by #91. So /cc @lorenzo

rchavik added a commit to croogo/croogo that referenced this issue Aug 23, 2019
@SunshineNoir
Copy link

Same bug is on Microsoft SQL server but there are no alternatives from above working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants