Skip to content

Conversation

@keulinho
Copy link
Contributor

Fixes #7027

Q A
Type bug
Fixed issues #7027

Summary

The length var was type string, which broke on the constructor of Column

@keulinho
Copy link
Contributor Author

removed test for varchar type as there seems to be no type mapping for that

@keulinho
Copy link
Contributor Author

i'm having trouble to add a pure reproducer in the testing setup here, see #7029

However I verified the fix locally inside shopware, see e.g. this workflow run for the issue: https://github.com/shopware/shopware/actions/runs/16268473345/job/45929737083?pr=11222

@derrabus
Copy link
Member

However I verified the fix locally inside shopware

I don't know much about Shopware's internals, but I'd like to understand why you're having this problem. Is Shopware maybe operating DBAL with the PDO::ATTR_STRINGIFY_FETCHES option enabled?

@keulinho
Copy link
Contributor Author

@derrabus yes exactly we are still relying on that option and it seems that the issue only shows with that option, so far I was unable to get that option into the testsuite here and for now stopped work on the reproducer, will happily continue with that when you provide the general direction e.g. if we even want to have a complete unit test run with that option?

@derrabus
Copy link
Member

Maybe we should add a CI job that runs the whole test suite with that option enabled. This option could be a potential footgun for every operation DBAL itself performs on the database. 🤔

@VincentLanglet
Copy link
Contributor

I can confirm the (important) bug.

The error can be found on the phpstan-doctrine CI https://github.com/phpstan/phpstan-doctrine/actions/runs/16344462764/job/46174534513

@derrabus derrabus added this to the 4.3.1 milestone Jul 21, 2025
@derrabus
Copy link
Member

@VincentLanglet The failure in PHPStan's CI that you're linking to shows a test failure that happens with Postgres. This issue discusses a bug inside the MySQL schema manager. Are you sure you provided the correct link?

@VincentLanglet
Copy link
Contributor

There is one failure, but also 950 errors like

1) PHPStan\Platform\QueryResultTypeWalkerFetchTypeMatrixTest::testPdoMysqlStringify with data set " -1" (array(array('1', true, null, 0.125, null, '0.1', null, 9, null, '2147483648', null, 'foobar', null, 1, DateTime Object (...))), 'SELECT -1 FROM %s t', PHPStan\Type\Constant\ConstantIntegerType Object (...), PHPStan\Type\Constant\ConstantIntegerType Object (...), PHPStan\Type\Constant\ConstantIntegerType Object (...), PHPStan\Type\Constant\ConstantIntegerType Object (...), PHPStan\Type\MixedType Object (...), -1, -1, -1, -1, -1, 'default')
TypeError: Doctrine\DBAL\Schema\Column::setLength(): Argument #1 ($length) must be of type ?int, string given, called in /home/runner/work/phpstan-doctrine/phpstan-doctrine/vendor/doctrine/dbal/src/Schema/Column.php on line 102

I thought this was related to the fact length was not caster to int.

@derrabus
Copy link
Member

There is one failure, but also 950 errors like

You're right, I missed those. My bad. Yes, this seems to be the same error.

Same question for you then: #7028 (comment)

@VincentLanglet
Copy link
Contributor

There is one failure, but also 950 errors like

You're right, I missed those. My bad. Yes, this seems to be the same error.

Same question for you then: #7028 (comment)

I dunno a lot about the logic behind the phpstan-doctrine tests, but the failure happen on some

$this->performDriverTest(
			'pdo_sqlite',
			self::CONFIG_STRINGIFY,
			$data,
			$dqlTemplate,
			(string) $this->dataName(),
			PHP_VERSION_ID,
			$sqliteExpectedType,
			$sqliteExpectedResult,
			$stringify,
		);

code with the map

private const CONNECTION_CONFIGS = [
		self::CONFIG_DEFAULT => [],
		self::CONFIG_STRINGIFY => [
			PDO::ATTR_STRINGIFY_FETCHES => true,
		],
		self::CONFIG_NO_EMULATE => [
			PDO::ATTR_EMULATE_PREPARES => false,
		],
		self::CONFIG_STRINGIFY_NO_EMULATE => [
			PDO::ATTR_STRINGIFY_FETCHES => true,
			PDO::ATTR_EMULATE_PREPARES => false,
		],
	];

So yes @derrabus indeed the failure occurs because there is a testcase with the option [PDO::ATTR_STRINGIFY_FETCHES](https://www.php.net/manual/en/pdo.constants.php#pdo.constants.attr-stringify-fetches).

@keulinho
Copy link
Contributor Author

i got the issue reproduced in the doctrine test suite by adding a job with stringify fetches, you can see it failing with the same error here: #7029

I'll cherry-pick the new testsuite to this PR and will make it green

Anything else you need before this is ready to merge?

*/
private function prepareExpectedRows(array $rows): array
{
if (! TestUtil::isDriverOneOf('ibm_db2', 'pdo_oci', 'pdo_sqlsrv', 'oci8')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This took quite some time for me to understand all the negated ifs, IMHO keeping the flow as straight forward as possible makes it easier to understand what is going on

if (! TestUtil::isDriverOneOf('ibm_db2')) {
if (
TestUtil::isDriverOneOf('pdo_oci', 'pdo_sqlsrv', 'oci8')
|| (TestUtil::getConnectionParams()['driverOptions'][PDO::ATTR_STRINGIFY_FETCHES] ?? false) === true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally did not check for pdo_mysqldriver as this would allow us to easily add the same job for other DB engines, if the ATTR_STRINGIFY_FETCHES option is relevant as well

@keulinho
Copy link
Contributor Author

@derrabus tests and CI is green now, I consider this finished so far, happy to get your review ;)

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Awesome work, thank you! Would you be interested in adding a CI job for the other PDO drivers as well?

@derrabus derrabus changed the title fix: Fix length type in MySQLSchemaManager Fix length type in MySQLSchemaManager with ATTR_STRINGIFY_FETCHES enabled Jul 22, 2025
@derrabus derrabus merged commit cbf95bb into doctrine:4.3.x Jul 22, 2025
87 checks passed
@keulinho
Copy link
Contributor Author

Thanks for quickly merging this! 🎉

PR for more jobs with that option is here: #7052

derrabus pushed a commit that referenced this pull request Jul 24, 2025
<!-- Fill in the relevant information below to help triage your pull
request. -->

|      Q       |   A
|------------- | -----------
| Type         | improvement

#### Summary

Add more unit test jobs that use the PDO::STRINGIFY_FETCHES option, as
discussed in this PR:
#7028 (review)

I didn't add a job for `pdo_oci` and `pdo_sqlsrv` as for those drivers
the result in `QueryBuilderTest` was already stringified, therefore I
assume those drivers always stringify the fetches, therefore a separate
job is not needed
derrabus added a commit that referenced this pull request Jul 26, 2025
* 4.3.x:
  feat: add more pdo jobs with stringify fetches (#7052)
  Fix case sensitivity in SQLite column types (#7050)
  Fix length type in `MySQLSchemaManager` with `ATTR_STRINGIFY_FETCHES` enabled (#7028)
  Fix Symfony 8 compatibility issues (#7009)
  Quote MySQL constraint names for foreign keys
derrabus added a commit to derrabus/dbal that referenced this pull request Jul 26, 2025
* 4.4.x:
  Document the JSON_OBJECT type (doctrine#7054)
  [RFC] Introduce Types::JSON_OBJECT (doctrine#7053)
  feat: add more pdo jobs with stringify fetches (doctrine#7052)
  Fix case sensitivity in SQLite column types (doctrine#7050)
  Fix length type in `MySQLSchemaManager` with `ATTR_STRINGIFY_FETCHES` enabled (doctrine#7028)
  Fix Symfony 8 compatibility issues (doctrine#7009)
  Quote MySQL constraint names for foreign keys
morozov pushed a commit to morozov/dbal that referenced this pull request Jul 27, 2025
* 4.4.x:
  Document the JSON_OBJECT type (doctrine#7054)
  [RFC] Introduce Types::JSON_OBJECT (doctrine#7053)
  feat: add more pdo jobs with stringify fetches (doctrine#7052)
  Fix case sensitivity in SQLite column types (doctrine#7050)
  Fix length type in `MySQLSchemaManager` with `ATTR_STRINGIFY_FETCHES` enabled (doctrine#7028)
  Fix Symfony 8 compatibility issues (doctrine#7009)
  Quote MySQL constraint names for foreign keys
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.

SchemaManager::listTableColumns() fails on DBAL 4.3.0 with binary column on MySql

3 participants