Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature/doctrine type guesser simple json array support#24297

Merged
fabpot merged 1 commit into
symfony:masterfrom
iluuu1994:feature/doctrine-type-guesser-simple-json-array-support
Sep 4, 2018
Merged

Feature/doctrine type guesser simple json array support#24297
fabpot merged 1 commit into
symfony:masterfrom
iluuu1994:feature/doctrine-type-guesser-simple-json-array-support

Conversation

@iluuu1994

Copy link
Copy Markdown
Contributor

Symfony currently supports doctrine/dbal ~2.4 which has support for both simple_array and json_array:

doctrine/dbal@44cd77f
doctrine/dbal@2d183ac

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

There's technically a small BC break since simple_array and json_array fields would've been displayed as simple text fields. Is this an acceptable BC break for Symfony 3.4?

@javiereguiluz javiereguiluz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this "technical BC break" really important? We could aso consider it a missing feature or bug: Doctrine DBAL will keep adding new methods and we need to update our guessers.

Maybe some Doctrine experts could point to more potential issues caused by this change? Thanks!

@jvasseur

Copy link
Copy Markdown
Contributor

The json_array can store a lot of things that aren't arrays so I'm 👎 for adding it.

@iluuu1994

Copy link
Copy Markdown
Contributor Author

@jvasseur Not according to the docs. The type will be casted to an array, at least when you're reading from the DB. json can be any type.

@jvasseur

Copy link
Copy Markdown
Contributor

The docs are wrong here, the code (https://github.com/doctrine/dbal/blob/2.5/lib/Doctrine/DBAL/Types/JsonArrayType.php#L63) shows that any non-null (database null, you can still get a null result with a json containing "null") value is just decoded. This means that a json_array type can be used to store booleans/strings/nulls. In fact the only difference between the json_array and json type is that the json type convert database nulls as php nulls instead of empty arrays.

And json_array columns can contains associative arrays that probably shouldn't be mapped to a collection type.

The array type to BTW can contains a lot more than arrays (even more than the json_array type) since it can convert anything that pass the php serialize function.

@iluuu1994

Copy link
Copy Markdown
Contributor Author

@jvasseur Point taken.

To be fair, the guesser uses MEDIUM_CONFIDENCE so it's not like we're claiming with absolute certainty that the type is going to be an array. But there's a pretty good change it is.

@nicolas-grekas

Copy link
Copy Markdown
Member

Moving to 4.1. Rebase on master might be needed, where PHP 7.1 features can be used btw.

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Oct 8, 2017
@iluuu1994 iluuu1994 changed the base branch from 3.4 to master October 8, 2017 16:45
@iluuu1994

Copy link
Copy Markdown
Contributor Author

@nicolas-grekas Done. When will the 4.0 branch be created?

@nicolas-grekas

Copy link
Copy Markdown
Member

Branch 4.0 will be created a few days before its release, so end of november.
Then, master will become the next 4.1.

@iluuu1994

Copy link
Copy Markdown
Contributor Author

@nicolas-grekas Ok! 👍

@Tobion Tobion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

JsonArray is deprecated since dbal 2.6 (https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Types/JsonArrayType.php#L28). So there is no point in adding support for it as a new feature. Also it's not safe anyway. The value is usually an array, but you can also encode scalar values as json which then does not return an array.
So the PR should be changed to only add support for simple_array.

@nicolas-grekas nicolas-grekas modified the milestones: 4.1, next Apr 20, 2018
switch ($metadata->getTypeOfField($property)) {
case Type::TARRAY:
case Type::SIMPLE_ARRAY:
case Type::JSON_ARRAY:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you remove JSON_ARRAY so that we can merge this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@iluuu1994

Copy link
Copy Markdown
Contributor Author

Removed support for json_array and rebased onto master.

@fabpot

fabpot commented Sep 4, 2018

Copy link
Copy Markdown
Member

Thank you @iluuu1994.

@fabpot fabpot merged commit 524bc4b into symfony:master Sep 4, 2018
fabpot added a commit that referenced this pull request Sep 4, 2018
…t (iluuu1994)

This PR was squashed before being merged into the 4.2-dev branch (closes #24297).

Discussion
----------

Feature/doctrine type guesser simple json array support

Symfony currently supports doctrine/dbal ~2.4 which has support for both `simple_array` and `json_array`:

doctrine/dbal@44cd77f
doctrine/dbal@2d183ac

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

There's technically a small BC break since `simple_array` and `json_array` fields would've been displayed as simple text fields. Is this an acceptable BC break for Symfony 3.4?

Commits
-------

524bc4b Feature/doctrine type guesser simple json array support
@iluuu1994 iluuu1994 deleted the feature/doctrine-type-guesser-simple-json-array-support branch September 4, 2018 16:51
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
This was referenced Nov 3, 2018
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.

7 participants