-
-
Notifications
You must be signed in to change notification settings - Fork 478
Fix default MySQL charset with doctrine/dbal > 2 #1481
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
Fix default MySQL charset with doctrine/dbal > 2 #1481
Conversation
3c23123 to
5340e68
Compare
5340e68 to
b78ad6b
Compare
Tests/ConnectionFactoryTest.php
Outdated
|
|
||
| $this->assertInstanceof(FakeConnection::class, $connection); | ||
| $this->assertSame('utf8', $connection->getParams()['charset']); | ||
| $this->assertSame('utf8mb4', $connection->getParams()['charset']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the FakeDriver is actually a MysqlPlatform that is why this test changees now.
ConnectionFactory.php
Outdated
|
|
||
| if (! isset($params['charset'])) { | ||
| if ($driver instanceof AbstractMySQLDriver) { | ||
| if ($driver->getDatabasePlatform()->getName() === 'mysql') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sadly calling a deprecated method but I could not find another method which works on this range of supported doctrine/dbal versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe by performing several instanceof checks?
Tests/ConnectionFactoryTest.php
Outdated
|
|
||
| $this->assertInstanceof(FakeConnection::class, $connection); | ||
| $this->assertSame('utf8', $connection->getParams()['charset']); | ||
| $this->assertSame('utf8mb4', $connection->getParams()['charset']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this is OK? It does not look OK to change that default value like that (I know it's a bad default, but it might result in a lot of migrations for a lot of people).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fake driver ist actually a mysqlplatform that is why it is changing :
| return static::$platform ?? new MySQLPlatform(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before the check was on the driver not on the platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 in fact, I think it might be fine, since people using MySQL ended up with utf8mb4 before #1456, but maybe we should rename the test to testDefaultCharsetForMySQL, and duplicate it with testDefaultCharsetForNonMySQL to test the other codepath with utf8
|
@greg0ire any idea how we can get the |
ConnectionFactory.php
Outdated
|
|
||
| if (! isset($params['charset'])) { | ||
| if ($driver instanceof AbstractMySQLDriver) { | ||
| if ($driver->getDatabasePlatform() instanceof AbstractMySQLPlatform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resulting Psalm error will have to be ignored through configuration I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with psalm do I need to ignore the whole file or is there another way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay seems @psalm-suppress UndefinedClass does the job
Let's improve the error message in the test first? "Failed asserting that false is true." is not very helpful |
|
Improved the message by using |
|
Is it maybe to early to access the platform because the platform is validated later here: DoctrineBundle/ConnectionFactory.php Line 110 in eb7f3a2
Which is the method the |
Ah nice catch. So this is caused by wiring the logging middlewares |
|
should target 2.5.x branch |
|
At that point I'm starting to think the way forward would be to make the middlewares opt-in, and throw if the charset is not specified when using them. So I think we should also deprecate not specifying the charset. Maybe @ostrolucky has an opinion to share on this as well? |
|
I share same opinion |
Co-authored-by: Grégoire Paris <postmaster@greg0ire.fr>
bf7ecc5 to
fbdd14a
Compare
2150f08 to
efa6531
Compare
efa6531 to
ee6f1ee
Compare
|
Thank you all 👍 |
The
$drivervariable can returnDoctrine\DBAL\Logging\Driverwhich is not instance ofAbstractMySQLDriver. So it need to be via the platform.Sadly
AbstractMySQLDriveris not available on prefer lowest so we need to check on the deprecatedgetNamemethod on the platform.fixes #1480