-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
base: main
Are you sure you want to change the base?
fix: parse text[] as array<string> #157
Conversation
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.
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 withassertSame()
- 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".'; |
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.
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\""}', |
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.
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, |
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.
Why was this changed?
@@ -43,7 +43,7 @@ public static function provideValidTransformations(): array | |||
0 => 'dfasdf', | |||
1 => 'qw,,e{q"we', | |||
2 => "'qrer'", | |||
3 => 604, |
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.
Why was this changed?
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: