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

make "use_savepoints = true" no-op with DBAL 4 #1773

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

dmaicher
Copy link
Contributor

While working on some bundles that support DBAL 3 and DBAL 4 I noticed that its quite a struggle to activate savepoints in a deprecation free way 😕

So I agree with @derrabus (see symfony/recipes#1290 (comment)) and propose to make this no-op with DBAL 4.

Fixes #1758

@ostrolucky
Copy link
Member

i'm fine with this

if (isset($connection['use_savepoints'])) {
// DBAL >= 4 always has savepoints enabled. So we only need to call "setNestTransactionsWithSavepoints" for DBAL < 4
if (method_exists(Connection::class, 'getEventManager')) {
if ($connection['use_savepoints']) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to empty it was actually never calling setNestTransactionsWithSavepoints(false). So I kept this behavior the same

@dmaicher dmaicher marked this pull request as ready for review March 17, 2024 08:41
@dmaicher dmaicher added this to the 2.12.0 milestone Mar 17, 2024
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should also conditionally deprecate the use_savepoints configuration node.

@dmaicher
Copy link
Contributor Author

Maybe you should also conditionally deprecate the use_savepoints configuration node.

Hm but then we still have deprecations? The idea was to just have use_savepoins = true without any deprecations

$def->addMethodCall('setNestTransactionsWithSavepoints', [$connection['use_savepoints']]);
}
} elseif (! $connection['use_savepoints']) {
throw new LogicException('The "use_savepoints" option can only be set to "true" when using DBAL >= 4');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is technically a breaking change for people on DBAL 4 using use_savepoints = false. As setNestTransactionsWithSavepoints was never called in those cases it did not result in any error. But this seems odd to me so I think having an error in those cases is the correct behavior.

@greg0ire
Copy link
Member

Hm but then we still have deprecations? The idea was to just have use_savepoins = true without any deprecations

Do you mean with DBAL 3 or 4? If not now, when do you plan to deprecate that configuration node?

@ostrolucky
Copy link
Member

ostrolucky commented Mar 17, 2024

@greg0ire Has a point. There is no point having use_savepoins (neither true nor false) in DBAL 4, because it's not configurable. When would we be able to remove this config node if people are fine with using it with dbal 4?

What's your struggle in configuring bundles supporting dbal3+4? With PHP config or TestKernel it should be quite easy to have dynamic switch.

@dmaicher
Copy link
Contributor Author

I was thinking to deprecate it once we drop DBAL 3 support 🤔

With PHP config or TestKernel it should be quite easy to have dynamic switch.

Yeah its doable but still a bit of a hassle 😢

@ostrolucky
Copy link
Member

ostrolucky commented Mar 17, 2024

I'm just thinking out loud: why don't we turn on savepoints by default? Do you think there would be some side-effects?

@dmaicher
Copy link
Contributor Author

I'm just thinking out loud: why don't we turn on savepoints by default? Do you think there would be some side-effects?

Possibly there could be some behavioral changes when doing nested transactions with rollbacks or so 🤔

Checking

https://github.com/doctrine/dbal/blob/db922ba9436b7b18a23d1653a0b41ff2369ca41c/src/Connection.php#L1380
https://github.com/doctrine/dbal/blob/db922ba9436b7b18a23d1653a0b41ff2369ca41c/src/Connection.php#L1541

@greg0ire do you think it would be fine to enable savepoints by default in a minor update?

@greg0ire
Copy link
Member

I don't think we should do that in behalf of users, no, otherwise we would have made setNestTransactionsWithSavepoints a no-op in DBAL 3 directly

@dmaicher
Copy link
Contributor Author

It would be nice if new projects (using DBAL 4) will not immediately see a deprecation caused by symfony/recipes#1290

Co-authored-by: Grégoire Paris <postmaster@greg0ire.fr>
@dmaicher dmaicher requested a review from greg0ire March 19, 2024 06:15
@greg0ire
Copy link
Member

It would be nice if new projects (using DBAL 4) will not immediately see a deprecation caused by symfony/recipes#1290

Maybe it's time to create a new major version of the bundle, that would drop DBAL 3 & 4, while still maintaining this one for a while, just like we do for ORM and DBAL? That way you could have a dedicated recipe.

@dmaicher dmaicher merged commit 6046a57 into doctrine:2.12.x Mar 19, 2024
14 checks passed
@dmaicher dmaicher deleted the issue_1758 branch March 19, 2024 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants