-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Type json_array is not consistent with NULL values #720
Conversation
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DBAL-1038 We use Jira to track the state of pull requests and the versions they got |
Hi, This was reported a couple of times already, but here is the explanation why it cannot be accepted as is: Many projects consume this data type and already deal currently with the []s, |
This is different from #538 and #655 |
This particular change makes sense to me, and is consistent with current behavior. It needs additional test cases and/or data-provider cases before merge though. |
agree. We need the following test in public function testJsonEmptyStringConvertsToPHPValue()
{
$this->assertSame(array(), $this->type->convertToPHPValue('', $this->platform));
} |
Ok, I have added a unit test. Any more tests that needs to be added? |
Should this be "back ported" to earlier versions of dbal? |
@TerjeBr it may be backported, yes |
What is the earliest version it should apply to? |
Likely 2.4.4. Right now, it only causes a warning because of |
What do you mean? what warning? |
I just figured that JsonArray was inluded in v2.5.0-BETA2 with commit 25e695f |
If you are talking about the Travis CI build failing, that failure is unrelated to this change. |
What was the behavior of this DBAL type with an empty string before the patch? |
Before the patch, an empty string in the DB was transformed into a NULL.
No warnings generated. |
Type json_array is not consistent with NULL values
Fields of type json_array are created as "TEXT NOT NULL", because they are not nullable by default.
If you have an existing table, and you add this field, all existing records will get an empty string as the value of the field and not NULL.
If you try to store a NULL value in that field, the database will convert it to an empty string.
The "convertToPHPValue" method for that type only checks for NULL when it converts NULL to array(), it does not check for an empty string.
The test must be changed to also test for the empty string, or else it behaves differently for when the column is set as nullable or not. And for the most common case, when the default vaule of letting the column be not nullable is used, this "feature" of converting blank values to empty arrays is not working.