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

Skip to content

Feature/doctrine type guesser simple json array support #24297

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

Conversation

iluuu1994
Copy link
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?

Copy link
Member

@javiereguiluz javiereguiluz left a comment

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
Contributor

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

@iluuu1994
Copy link
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
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
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.

@iluuu1994 iluuu1994 force-pushed the feature/doctrine-type-guesser-simple-json-array-support branch from f755bb4 to 958a8b2 Compare October 5, 2017 21:00
@nicolas-grekas
Copy link
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 force-pushed the feature/doctrine-type-guesser-simple-json-array-support branch from 958a8b2 to c08426b Compare October 8, 2017 16:44
@iluuu1994 iluuu1994 changed the base branch from 3.4 to master October 8, 2017 16:45
@iluuu1994
Copy link
Contributor Author

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

@iluuu1994 iluuu1994 force-pushed the feature/doctrine-type-guesser-simple-json-array-support branch from c08426b to 25060b4 Compare October 8, 2017 16:50
@nicolas-grekas
Copy link
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
Contributor Author

@nicolas-grekas Ok! 👍

Copy link
Contributor

@Tobion Tobion left a comment

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
@@ -53,6 +53,8 @@ public function guessType($class, $property)

switch ($metadata->getTypeOfField($property)) {
case Type::TARRAY:
case Type::SIMPLE_ARRAY:
case Type::JSON_ARRAY:
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

Done.

@iluuu1994 iluuu1994 force-pushed the feature/doctrine-type-guesser-simple-json-array-support branch from 25060b4 to 8c7fbe9 Compare September 4, 2018 16:05
@iluuu1994 iluuu1994 force-pushed the feature/doctrine-type-guesser-simple-json-array-support branch from 8c7fbe9 to 00a72ad Compare September 4, 2018 16:07
@iluuu1994
Copy link
Contributor Author

Removed support for json_array and rebased onto master.

@fabpot fabpot force-pushed the feature/doctrine-type-guesser-simple-json-array-support branch from 00a72ad to 524bc4b Compare September 4, 2018 16:49
@fabpot
Copy link
Member

fabpot commented Sep 4, 2018

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