Skip to content

[Validator] Deprecate Constraint::$errorNames in favor of Constraint::ERROR_NAMES #45371

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
Feb 10, 2022

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Feb 9, 2022

Q A
Branch? 6.1
Bug fix? no
New feature? no
Deprecations? yes
Tickets -
License MIT
Doc PR -

On the road to #43600

The BC layer is a bit light, but since this property seems like a piece of declarative statement that should we accessed only through Contraint::getErrorName(), I suggest doing it this way, and improve only if/when we get feedback from userland about it.

@derrabus
Copy link
Member

derrabus commented Feb 9, 2022

I can't help myself, but I always find it weird to override a constant. Designing an API around that feels even weirder. An alternative approach could be to move constraints towards overriding Constraint::getErrorName() instead. That method could be implemented with a simple match expression.

@nicolas-grekas
Copy link
Member Author

@derrabus mmmm :) This API is just a declarative piece of code, it needs only a constant, not runtime logic.

Copy link
Contributor

@fancyweb fancyweb left a comment

Choose a reason for hiding this comment

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

Could we add a runtime deprecation on Constraint::getErrorName() if the error code is found in the deprecated property but not in the new constant to help understand the vague deprecation "The "Symfony\Component\Validator\Constraint::$errorNames" property is considered final. You should not override it in XX that will be triggered on every custom constraint overriding the property?

@nicolas-grekas nicolas-grekas added this to the 6.1 milestone Feb 9, 2022
@carsonbot carsonbot changed the title [Validator] Deprecate Constraint::$errorNames in favor of Constraint::ERROR_NAMES Deprecate Constraint::$errorNames in favor of Constraint::ERROR_NAMES Feb 9, 2022
@carsonbot carsonbot changed the title Deprecate Constraint::$errorNames in favor of Constraint::ERROR_NAMES [Validator] Deprecate Constraint::$errorNames in favor of Constraint::ERROR_NAMES Feb 9, 2022
@ro0NL
Copy link
Contributor

ro0NL commented Feb 9, 2022

do we understand the purpose of getErrorName? If so, would it be reasonable to have a dynamic default implementation? If not, could we deprecate it?

https://symfony.com/doc/current/validation/custom_constraint.html#creating-the-constraint-class
https://github.com/symfony/symfony/search?q=getErrorName

@fancyweb
Copy link
Contributor

do we understand the purpose of getErrorName?

See #12021

@ro0NL
Copy link
Contributor

ro0NL commented Feb 10, 2022

The getErrorName() method is especially helpful for REST APIs, where you can return both an error code and a description of that error now.

i don't think getErrorName is that useful :) from the constraint violation POV your have the code+message

@nicolas-grekas
Copy link
Member Author

@ro0NL that discussion is unrelated to the PR. We have to keep things working. Please open an issue if you want to have a discussion about this method.

@ro0NL
Copy link
Contributor

ro0NL commented Feb 10, 2022

i think 1 migration path is enough for a while :)

thus either deal with "deprecated prop", or deal with "deprecated method"

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Feb 10, 2022

This PR is motivated by #45360: deprecating the properties is required for it.

Deprecating the method is not motivated by any actual data. We actually have data that supports the method: someone contributed it. So clearly this shows the path to me.

@nicolas-grekas
Copy link
Member Author

Could we add a runtime deprecation on Constraint::getErrorName() if the error code is found in the deprecated property

good idea, updated.

@nicolas-grekas nicolas-grekas merged commit fa61d6e into symfony:6.1 Feb 10, 2022
@nicolas-grekas nicolas-grekas deleted the no-error-names-prop branch February 10, 2022 10:17
@fabpot fabpot mentioned this pull request Apr 15, 2022
damienalexandre added a commit to damienalexandre/nir-validation that referenced this pull request Sep 25, 2023
damienalexandre added a commit to damienalexandre/nir-validation that referenced this pull request Sep 26, 2023
roukmoute pushed a commit to assurance-maladie-digital/nir-validation that referenced this pull request Sep 26, 2023
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.

5 participants