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 |
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
Closed
githubjeka opened this issue
Nov 10, 2016
· 10 comments
Comments
What are you trying to achieve?
Install advanced Yii2
run tests
Time: 7.66 seconds, Memory: 28.00MB
OK (24 tests, 67 assertions)
Add to site/index code:
public function actionIndex() { $tr = Yii::$app->db->beginTransaction(); $tr->commit(); return $this->render('index'); }
run tests
> [yiidbException] SQLSTATE[42000]: Syntax error or access violation: 1305 SAVEPOINT LEVEL1 does not exist The SQL being executed was: RELEASE SAVEPOINT LEVEL1 ERRORS! Tests: 24, Assertions: 66, Errors: 1.
Details
- Codeception version: 2.2.6
- PHP Version: 7.0.5
- Operating System: Windows 10
- Mysql 5.7.10
Copy link
Contributor
Author
I tried:
class_name: FunctionalTester modules: enabled: - Yii2: cleanup: false
try to set in http://www.yamllint.com/ is Valid
To fix my problem need to use
class_name: FunctionalTester modules: enabled: - Yii2: cleanup: false
F%^%k
Copy link
Contributor
Author
Is it correct ?
No, there is no {}
in YAML format. YAML is set with spaces. In your 1st config you didn’t specify space for cleanup: false
as it was required.
In your working example you had more than enough spaces. Just remember, 4 spaces is usually OK for yaml. THis conifg should work as well
class_name: FunctionalTester modules: enabled: - Yii2: cleanup: false
No, there is no {} in YAML format
There is, it is called flow style
.
Copy link
Contributor
Author
Just remember, 4 spaces is usually OK for yaml.
Now I know about it from you, but debug of this is a pain.
If you think that it not should be described in documentation, you can close this issue. Thanks.
There is, it is called flow style.
Ups, I’m so old-fashioned
If you think that it not should be described in documentation, you can close this issue. Thanks.
We have lots pages of documentation and I have no idea where better to place this notice. But thanks for the suggestion. I think we can make some validator to debug such issues
@githubjeka yep, I think I have an idea how to improve things. Please check my proposal at #3766
Hello, @DavertMik! I encountered the same error. https://imgur.com/a/Uitxz0K
yiisofy/yii2: 2.0.39.3
codeception/codeception: 4.1.12
I checked the config with the command php vendor/bin/codecept config:validate
, everything is fine.
What could be the problem?
@Subb98 have you set cleanup: false
in api.suite.yaml ? (I have no idea how it is relevant, but it was mentioned in comments above).
Also you said that you are using codeception/codeception: 4.1.12 but your screeshot shows that you used 3.1.2
@Naktibalda thank you for your prompt response. The problem was the missing table. Sorry for the necroposting )
Data should be cleaned up in two associated tables
I’ll take an example from the textbook, and I’ll make some changes.
$transaction = $this->connection->beginTransaction();
try {
// $this->connection->createCommand()->truncateTable($this->sectionLangTable)->execute();
// $this->connection->createCommand()->truncateTable($this->sectionTable)->execute();
$this->connection->createCommand('SET foreign_key_checks = 0')->execute();
$this->connection->createCommand('DELETE FROM '.$this->sectionLangTable)->execute();
$this->connection->createCommand('DELETE FROM '.$this->sectionTable)->execute();
$this->connection->createCommand('ALTER TABLE '.$this->sectionTable.' AUTO_INCREMENT=1')->execute();
$this->connection->createCommand('SET foreign_key_checks = 1')->execute();
$transaction->commit();
return true;
} catch (Exception $e) {
$error = $e->getMessage();
$transaction->rollBack();
return false;
}
It ends with the exception.
Syntax error or access violation: 1305 SAVEPOINT LEVEL1 does not exist
The SQL being executed was: RELEASE SAVEPOINT LEVEL1
The exception arises at the time commit or rollback.
First, I tried what was buried, too.
The Google mostly results from the Codeception and its configurations.
Then there’s talk about not keeping mysql intact.
But according to the logs, there’s one transaction.
2018-02-27 12:04:05 [-][-][-][trace][yiibaseApplication::bootstrap] Bootstrap with yiilogDispatcher
2018-02-27 12:04:05 [-][-][-][trace][yiibaseModule::getModule] Loading module: gii
2018-02-27 12:04:05 [-][-][-][trace][yiibaseApplication::bootstrap] Bootstrap with yiigiiModule::bootstrap()
2018-02-27 12:04:05 [-][-][-][trace][yiibaseController::runAction] Route to run: migrate/up
2018-02-27 12:04:05 [-][-][-][trace][yiibaseInlineAction::runWithParams] Running action: yiiconsolecontrollersMigrateController::actionUp()
2018-02-27 12:04:05 [-][-][-][trace][yiidbTransaction::begin] Begin transaction
2018-02-27 12:04:05 [-][-][-][trace][yiidbTransaction::begin] Set savepoint 1
in D:wwwedusiteshtdocscommoncomponentssitemaprepositorySitemapRepository.php:156
in D:wwwedusiteshtdocsconsolecomponentsmigrationhandlersInitialInfoHandler.php:32
in D:wwwedusiteshtdocsconsolemigrationsdatam180214_092839_menu_initial.php:18
2018-02-27 12:04:05 [-][-][-][trace][yiidbTransaction::commit] Release savepoint 1
in D:wwwedusiteshtdocscommoncomponentssitemaprepositorySitemapRepository.php:165
in D:wwwedusiteshtdocsconsolecomponentsmigrationhandlersInitialInfoHandler.php:32
in D:wwwedusiteshtdocsconsolemigrationsdatam180214_092839_menu_initial.php:18
2018-02-27 12:04:05 [-][-][-][trace][yiidbTransaction::rollBack] Roll back transaction
in D:wwwedusiteshtdocscommoncomponentssitemaprepositorySitemapRepository.php:170
in D:wwwedusiteshtdocsconsolecomponentsmigrationhandlersInitialInfoHandler.php:32
in D:wwwedusiteshtdocsconsolemigrationsdatam180214_092839_menu_initial.php:18
The data from the tables are still clean.
Please help.
P.S. While rereading the post, he saw that there was no word LEVEL in the slogan and there was an exception. It might be a problem, but it’s kind of weird.
P.S.2 is the same, but instead of removal, insert works well.
2018-02-27 12:24:51 [-][-][-][trace][yiibaseApplication::bootstrap] Bootstrap with yiilogDispatcher
2018-02-27 12:24:51 [-][-][-][trace][yiibaseModule::getModule] Loading module: gii
2018-02-27 12:24:51 [-][-][-][trace][yiibaseApplication::bootstrap] Bootstrap with yiigiiModule::bootstrap()
2018-02-27 12:24:51 [-][-][-][trace][yiibaseController::runAction] Route to run: migrate/up
2018-02-27 12:24:51 [-][-][-][trace][yiibaseInlineAction::runWithParams] Running action: yiiconsolecontrollersMigrateController::actionUp()
2018-02-27 12:24:52 [-][-][-][trace][yiidbTransaction::begin] Begin transaction
2018-02-27 12:24:52 [-][-][-][trace][yiidbTransaction::begin] Set savepoint 1
in D:wwwedusiteshtdocscommoncomponentssitemaprepositorySitemapRepository.php:155
in D:wwwedusiteshtdocsconsolecomponentsmigrationhandlersInitialInfoHandler.php:32
in D:wwwedusiteshtdocsconsolemigrationsdatam180214_092839_menu_initial.php:18
2018-02-27 12:24:52 [-][-][-][trace][yiidbTransaction::commit] Release savepoint 1
in D:wwwedusiteshtdocscommoncomponentssitemaprepositorySitemapRepository.php:165
in D:wwwedusiteshtdocsconsolecomponentsmigrationhandlersInitialInfoHandler.php:32
in D:wwwedusiteshtdocsconsolemigrationsdatam180214_092839_menu_initial.php:18
2018-02-27 12:24:52 [-][-][-][trace][yiidbTransaction::commit] Commit transaction