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

fix: parse text[] as array<string> #157

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

adrienbrault
Copy link

Hey,

The way MartinGeorgiev\Doctrine\DBAL\Types\TextArray converts database values to php floats/int broke my expectations.

When I save ['a', '1', '0.1'] to my database, I expect to get back the same ['a', '1', '0.1'], NOT ['a', 1, 0.1]. Especially when the column name is "text".

I also checked postgres itself, and there is no magic casting:

database=# select pg_typeof(('{0.4}'::text[])[1]);
 pg_typeof
-----------
 text
(1 row)

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR fixes type handling in PostgreSQL text arrays by ensuring numeric values remain as strings rather than being automatically converted to integers/floats.

  • Modified src/MartinGeorgiev/Utils/DataStructure.php to preserve string types for numeric values in text arrays
  • Updated tests/MartinGeorgiev/Doctrine/DBAL/Types/TextArrayTest.php to use strict type checking with assertSame()
  • Adjusted test data in tests/MartinGeorgiev/Utils/DataStructureTest.php to properly handle numeric values as strings
  • Aligned behavior with PostgreSQL's native text[] type which maintains all elements as strings

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

3 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile


continue;
}

if (!\is_string($text)) {
$exceptionMessage = 'Unsupported data type encountered. Expected null, integer, float or string value. Instead it is "%s".';
Copy link

Choose a reason for hiding this comment

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

logic: Error message mentions expecting integer/float values but code no longer handles these types

@@ -43,7 +43,7 @@ public static function provideValidTransformations(): array
0 => 'dfasdf',
1 => 'qw,,e{q"we',
2 => "'qrer'",
3 => 604,
3 => '604',
4 => '"aaa","b""bb","ccc"',
],
'postgresValue' => '{"dfasdf","qw,,e{q\"we","\'qrer\'",604,"\"aaa\",\"b\"\"bb\",\"ccc\""}',
Copy link

Choose a reason for hiding this comment

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

logic: Mismatch between test data - phpValue has '604' as string but postgresValue has 604 as unquoted number. This will cause type inconsistency.

@@ -44,7 +44,7 @@ public static function provideValidTransformations(): array
],
[
'phpValue' => [
1,
Copy link
Owner

Choose a reason for hiding this comment

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

Why was this changed?

@@ -43,7 +43,7 @@ public static function provideValidTransformations(): array
0 => 'dfasdf',
1 => 'qw,,e{q"we',
2 => "'qrer'",
3 => 604,
Copy link
Owner

Choose a reason for hiding this comment

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

Why was this changed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants