yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT LEVEL1 does not exist #13925

Closed bscheshirwork closed 7 years ago

bscheshirwork commented 7 years ago

What steps will reproduce the problem?

create functional test with

class_name: FunctionalTester
modules:
    enabled:
        - Yii2

.codecept/src/Codeception/Lib/Connector/Yii2.php

create backend/tests/functional/CreateUserCest.php used Yii inner browser https://github.com/bscheshirwork/yii2-app-advanced-rbac/blob/8ab2bfdae8cd30d1b09931aaeb931ce07880b7ab/backend/tests/functional/CreateUserCest.php

create nested transaction (MySQL 5.6.35 | 5.7.17 | 8.0.0) just like transactional save vendor/dektrium/yii2-user/models/User.php

        $transaction = $this->getDb()->beginTransaction();

        try {
            $this->password = $this->password == null ? Password::generate(8) : $this->password;

            $this->trigger(self::BEFORE_CREATE);

            if (!$this->save()) {
                $transaction->rollBack();
                return false;
            }

            $this->confirm();

            $this->mailer->sendWelcomeMessage($this, null, true);
            $this->trigger(self::AFTER_CREATE);

            $transaction->commit();

            return true;
        } catch (\Exception $e) {
            $transaction->rollBack();
            \Yii::warning($e->getMessage());
            throw $e;
        }

What is the expected result?

created next _level savepoint / release last _level savepoint

What do you get instead?

execute savepoint but no execute release rise error SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT LEVEL1 does not exist

Additional info

Exaggerating releaseSavepoint raise error https://github.com/yiisoft/yii2/blob/master/framework/db/Transaction.php#L137

        $schema = $this->db->getSchema();
        if ($schema->supportsSavepoint()) {
            Yii::trace('Set savepoint ' . $this->_level, __METHOD__);
            $schema->createSavepoint('LEVEL' . $this->_level);
            $schema->releaseSavepoint('LEVEL' . $this->_level);
        } else {
            Yii::info('Transaction not started: nested transaction not supported', __METHOD__);
        }
Q A
Yii version 2.0.?

yiisoft/yii2 dev-master c586f19 | PHP version | 7.1.3 | Operating system |debian https://github.com/bscheshirwork/docker-yii2-app-advanced-rbac/blob/master/docker-codeception-run/docker-compose.yml

samdark commented 7 years ago

Is that Codeception only error?

bscheshirwork commented 7 years ago

Hm.. Yes.

I think it .codecept/src/Codeception/Lib/Connector/Yii2.php error

    public function _before(FunctionalTester $I)
    {
        Yii::$app->db->close();
        Yii::$app->db->beginTransaction();
    }

avoid this error

samdark commented 7 years ago

Then it should be reported to https://github.com/Codeception/Codeception/ and fixed there.