Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FixConstraintViolation#getPropertyPath() to always returnstring#40415

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@Ocramius
Copy link
Contributor

QA
Branch?5.2
Bug fix?yes
New feature?no
Deprecations?no
Tickets
LicenseMIT
Doc PR

ConstraintViolation#getPropertyPath()'s inherited signature states thatstring is
to be returned by it at all times, yet the implementation returnsnull when no property
path had been provided at instantiation.

This patch obviates it, returning an empty string when the
property path isnull.

dunglas reacted with thumbs up emoji
`ConstraintViolation#getPropertyPath()`'s inherited signature states that `string` isto be returned by it at all times, yet the implementation returns `null` when no propertypath had been provided at instantiation.This patch obviates it, returning an empty string when theproperty path is `null`.
@Ocramius
Copy link
ContributorAuthor

Integration test suite failure seems unrelated

derrabus reacted with thumbs up emoji

@derrabus
Copy link
Member

Good catch. We have the same problem with the$messageTemplate property in that class if I'm not mistaken. In both cases, I'd suggest to perform the string cast inside the constructor already. Either way, it looks like a mistake to me that we allownull to be passed to the constructor.

@Ocramius
Copy link
ContributorAuthor

Either way, it looks like a mistake to me that we allownull to be passed to the constructor.

That ship has sailed though, and there's active design around the property path being missing.

@derrabus
Copy link
Member

That ship has sailed though, and there's active design around the property path being missing.

Yeah, for sure, we cannot just change the type now. But if it's a mistake, we could try to correct it for Symfony 6. The parameter types for$propertyPath and$messageTemplate have been added with#24722 despite the PHPDoc block documenting those parameters as non-nullable.

Our own code (ExecutionContext::addViolation() andConstraintViolationBuilder::addViolation()) should make sure that we don't passnull to either of them. May I ask how you got yourself aConstraintViolation instance with anull property path? Maybe I missed something.

@Ocramius
Copy link
ContributorAuthor

Our own code (ExecutionContext::addViolation() andConstraintViolationBuilder::addViolation()) should make sure that we don't passnull to either of them. May I ask how you got yourself aConstraintViolation instance with anull property path? Maybe I missed something.

I was copying violations reported from one validator to another, pretty much likeConstraintViolationBuilderInterface#atPath(ConstraintViolationInterface#getPropertyPath())

@Nyholm
Copy link
Member

Thank you. Could you do the same fix for the$messageTemplate please? The same bug is forgetMessageTemplate() too.

@Ocramius
Copy link
ContributorAuthor

Will send a separate patch

Nyholm reacted with thumbs up emoji

Ocramius added a commit to Ocramius/symfony that referenced this pull requestMar 8, 2021
`ConstraintViolation#getMessageTemplate()`'s inherited signature states that `string` isto be returned by it at all times, yet the implementation returns `null` when no messagetemplate had been provided at instantiation.This patch obviates it, returning an empty string when themessage template is `null`.Ref:symfony#40415 (comment)
@derrabus
Copy link
Member

I still think we should perform the string cast inside the constructor though. 🙃

btw: is the 4.4 branch affected as well?

ro0NL reacted with thumbs up emoji

@Nyholm
Copy link
Member

Hm, the small benefit to cast it to a string in the constructor is that we can remove the cast in the__toString() method.

derrabus reacted with thumbs up emoji

@Ocramius
Copy link
ContributorAuthor

Ocramius commentedMar 8, 2021
edited
Loading

I still think we should perform the string cast inside the constructor though. upside_down_face

You do that, you break subclassing types for little benefit.

I can imagine that some subclassing will likely rely on the fact that$this->foo !== null to take internal decisions.

EDIT: keep in mind that the scope of this is abugfix, not a refactoring. That would probably target5.x instead.

@Ocramius
Copy link
ContributorAuthor

btw: is the 4.4 branch affected as well?

Possibly, didn't check, since I'd rather leave 4.4 alone. This is the sort of bugfix that I would never ever want to see in an LTS, since there's a subtle change in behavior.

@derrabus
Copy link
Member

I still think we should perform the string cast inside the constructor though. upside_down_face

You do that, you break subclassing types for little benefit.

$propertyPath is declared private, so a subclass would need access it via the very same getter that you are patching right now.

@Ocramius
Copy link
ContributorAuthor

Ah, true that 👍

@fabpot
Copy link
Member

Thank you@Ocramius.

@fabpotfabpot merged commite5f9a89 intosymfony:5.2Mar 10, 2021
fabpot pushed a commit to Ocramius/symfony that referenced this pull requestMar 10, 2021
`ConstraintViolation#getMessageTemplate()`'s inherited signature states that `string` isto be returned by it at all times, yet the implementation returns `null` when no messagetemplate had been provided at instantiation.This patch obviates it, returning an empty string when themessage template is `null`.Ref:symfony#40415 (comment)
Ocramius added a commit to Ocramius/symfony that referenced this pull requestMar 10, 2021
`ConstraintViolation#getMessageTemplate()`'s inherited signature states that `string` isto be returned by it at all times, yet the implementation returns `null` when no messagetemplate had been provided at instantiation.This patch obviates it, returning an empty string when themessage template is `null`.Ref:symfony#40415 (comment)
@fabpotfabpot mentioned this pull requestMar 10, 2021
fabpot added a commit that referenced this pull requestMar 11, 2021
…eturn `string` (Ocramius)This PR was merged into the 5.2 branch.Discussion----------Fix `ConstraintViolation#getMessageTemplate()` to always return `string`| Q             | A| ------------- | ---| Branch?       | 5.2| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       || License       | MIT| Doc PR        |`ConstraintViolation#getMessageTemplate()`'s inherited signature states that `string` isto be returned by it at all times, yet the implementation returns `null` when no messagetemplate had been provided at instantiation.This patch obviates it, returning an empty string when themessage template is `null`.Ref:#40415 (comment)Commits-------72a464e Fix `ConstraintViolation#getMessageTemplate()` to always return `string`
symfony-splitter pushed a commit to symfony/validator that referenced this pull requestMar 11, 2021
`ConstraintViolation#getMessageTemplate()`'s inherited signature states that `string` isto be returned by it at all times, yet the implementation returns `null` when no messagetemplate had been provided at instantiation.This patch obviates it, returning an empty string when themessage template is `null`.Ref:symfony/symfony#40415 (comment)
symfony-splitter pushed a commit to symfony/validator that referenced this pull requestMar 11, 2021
…eturn `string` (Ocramius)This PR was merged into the 5.2 branch.Discussion----------Fix `ConstraintViolation#getMessageTemplate()` to always return `string`| Q             | A| ------------- | ---| Branch?       | 5.2| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       || License       | MIT| Doc PR        |`ConstraintViolation#getMessageTemplate()`'s inherited signature states that `string` isto be returned by it at all times, yet the implementation returns `null` when no messagetemplate had been provided at instantiation.This patch obviates it, returning an empty string when themessage template is `null`.Ref:symfony/symfony#40415 (comment)Commits-------72a464e449 Fix `ConstraintViolation#getMessageTemplate()` to always return `string`
@OcramiusOcramius deleted the fix/ensure-property-path-respects-declared-interface-type branchMarch 25, 2021 19:21
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@NyholmNyholmNyholm approved these changes

@derrabusderrabusderrabus approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

5.2

Development

Successfully merging this pull request may close these issues.

5 participants

@Ocramius@derrabus@Nyholm@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp