8000 [Form] trigger deprecation warning when using empty_value by xabbuh · Pull Request #15945 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] trigger deprecation warning when using empty_value #15945

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

Merged
merged 1 commit into from
Nov 7, 2015

Conversation

xabbuh
Copy link
Member
@xabbuh xabbuh commented Sep 27, 2015
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #15908
License MIT
Doc PR

The empty_value option is deprecated in the choice, date, and
time form types. Therefore, a deprecation warning must be triggered
when the users configures a value for this option.

The datetime form type does not need to be updated as it passes
configured values to the date and time form types which trigger
deprecation warnings anyway.

@wouterj
Copy link
Member
wouterj commented Sep 27, 2015

Other implementations of renamed options default the original option to null and use the old option if not null or use the default of the new option instead. Is there any reason to implement this in another way?

@xabbuh
Copy link
Member Author
xabbuh commented Sep 27, 2015

@wouterj Do you have an example?

@wouterj
Copy link
Member
wouterj commented Sep 27, 2015

@xabbuh
Copy link
Member Author
xabbuh commented Sep 27, 2015

@wouterj The thing is that the default value of the empty_value option depends on the value 8000 of the required option. I am not sure if the code were really readable when we made a similar change here.

@Tobion
Copy link
Contributor
Tobion commented Sep 27, 2015

The virtual example is non-optimal as well. Best appraoch is (which I used for the options i deprecated).

  • old option defaults to null
  • new option has new default
  • new option has normalizer that triggers error if old option != null and uses that value instead

Otherwise deprecations would not be triggered if the new option is overwritten but the old option is still used (which would then break in 3.0 as the option doesn't exist anymore).

@wouterj
Copy link
Member
wouterj commented Sep 27, 2015

Hmm, the actual problem here is that null is completely valid as a value for placeholder/empty_value. So someone explicitely configuring 'empty_value' => null should be catched as a deprecated usage (and if the default is '' but null was configured explicitely, it should be null and not '').

@Tobion
Copy link
Contributor
Tobion commented Sep 27, 2015

Just use a different value as default then that doesn't have a real meaning,e .g. true.

@@ -179,7 +179,11 @@ public function configureOptions(OptionsResolver $resolver)
return $options['required'] ? null : '';
};

$placeholder = function (Options $options) {
$placeholder = function (Options $options) use ($emptyValue) {
if ($emptyValue !== $options['empty_value']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This cannot work anyway from what I can see. $emptyValue is a closure.

@Tobion
Copy link
Contributor
Tobion commented Sep 27, 2015

Status: Needs Work

The `empty_value` option is deprecated in the `choice`, `date`, and
`time` form types. Therefore, a deprecation warning must be triggered
when the users configures a value for this option.

The `datetime` form type does not need to be updated as it passes
configured values to the `date` and `time` form types which trigger
deprecation warnings anyway.
@xabbuh
Copy link
Member Author
xabbuh commented Nov 4, 2015

I updated here.

Status: Needs Review

@@ -328,7 +329,7 @@ public function configureOptions(OptionsResolver $resolver)
'preferred_choices' => array(),
'group_by' => null,
'empty_data' => $emptyData,
'empty_value' => $emptyValue, // deprecated
'empty_value' => new \Exception(), // deprecated
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not really nice, but as the empty value can be nearly everthing it was best I could think of.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's quite unfortunate choice, as exceptions include stacktrace, which can cause circular references if used in functional tests. My Behat test suite with new \Exception() uses 200MB of memory, but with null it only uses 103MB. Can we use some other object instead? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

see #20425

@fabpot
Copy link
Member
fabpot commented Nov 7, 2015

Thank you @xabbuh.

@fabpot fabpot merged commit 405d4a8 into symfony:2.7 Nov 7, 2015
fabpot added a commit that referenced this pull request Nov 7, 2015
…(xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form] trigger deprecation warning when using empty_value

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

The `empty_value` option is deprecated in the `choice`, `date`, and
`time` form types. Therefore, a deprecation warning must be triggered
when the users configures a value for this option.

The `datetime` form type does not need to be updated as it passes
configured values to the `date` and `time` form types which trigger
deprecation warnings anyway.

Commits
-------

405d4a8 trigger deprecation warning when using empty_value
@xabbuh xabbuh deleted the issue-15908 branch November 7, 2015 08:33
@fabpot fabpot mentioned this pull request Nov 23, 2015
fabpot added a commit that referenced this pull request Dec 3, 2016
This PR was merged into the 2.7 branch.

Discussion
----------

[Form] fixed "empty_value" option deprecation

| Q             | A
| ------------- | ---
| Branch?       | 2.x only
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15945 (comment)
| License       | MIT
| Doc PR        | ~

I didn't make any profiling but a resolver instance is passed to `configureOptions()` creating locale variables including those exceptions for each field using one of the patched form types, so I guess the memory usage can grow really fast.

Commits
-------

7e84907 [Form] fixed "empty_value" option deprecation
symfony-splitter pushed a commit to symfony/form that referenced this pull request Dec 3, 2016
This PR was merged into the 2.7 branch.

Discussion
----------

[Form] fixed "empty_value" option deprecation

| Q             | A
| ------------- | ---
| Branch?       | 2.x only
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#15945 (comment)
| License       | MIT
| Doc PR        | ~

I didn't make any profiling but a resolver instance is passed to `configureOptions()` creating locale variables including those exceptions for each field using one of the patched form types, so I guess the memory usage can grow really fast.

Commits
-------

7e84907 [Form] fixed "empty_value" option deprecation
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
0