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

[Validator] Throw ValidatorException when validating non-existent property#62238

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

Open
mlussi90 wants to merge2 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
frommlussi90:7.4

Conversation

@mlussi90
Copy link

@mlussi90mlussi90 commentedOct 30, 2025
edited by nicolas-grekas
Loading

QA
Branch?7.4
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#62198
LicenseMIT

This fixes issue#62198 by adding validation checks in validateProperty() and validatePropertyValue() methods to ensure the property exists before attempting validation. If a property does not exist, a ValidatorException is thrown with an appropriate error message.

The implementation uses hasPropertyMetadata() to check if the property exists before calling getPropertyMetadata(), which prevents silent failures when properties are removed or renamed.

This fixes issuesymfony#62198 by adding validation checks in validateProperty()and validatePropertyValue() methods to ensure the property exists beforeattempting validation. If a property does not exist, a ValidatorExceptionis thrown with an appropriate error message.The implementation uses hasPropertyMetadata() to check if the propertyexists before calling getPropertyMetadata(), which prevents silentfailures when properties are removed or renamed.
@carsonbotcarsonbot added this to the7.4 milestoneOct 30, 2025
@carsonbotcarsonbot changed the titleThrow ValidatorException when validating non-existent property Throw ValidatorException when validating non-existent propertyOct 30, 2025
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

Previously, the check only verified if metadata exists, which causedtests to fail for properties that exist but have no constraints defined.Now the check verifies if the property actually exists in the class(using property_exists or getter methods) before throwing an exception.This allows validating properties without constraints, which shouldreturn 0 violations, while still throwing an exception for propertiesthat don't exist at all.
@carsonbotcarsonbot changed the title Throw ValidatorException when validating non-existent property[Validator] Throw ValidatorException when validating non-existent propertyOct 31, 2025

if (!$classMetadata->hasPropertyMetadata($propertyName)) {
$className =\is_object($object) ?$object::class :$object;
if (!property_exists($className,$propertyName) && !method_exists($className,'get'.ucfirst($propertyName)) && !method_exists($className,'is'.ucfirst($propertyName)) && !method_exists($className,'has'.ucfirst($propertyName))) {
Copy link
Member

@nicolas-grekasnicolas-grekasOct 31, 2025
edited
Loading

Choose a reason for hiding this comment

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

this doesn't look appropriate to me: these checks rely on knowledge about what's a property that's none of this class' business

@santysisi
Copy link
Contributor

From the issue and PR description, it looks like this change will throw an error if the property doesn’t exist.

Right now it just does nothing, so changing that might be a breaking change.

Maybe we could trigger a warning or deprecation or error message in this version and throw the error in the next major version?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

Assignees

No one assigned

Projects

None yet

Milestone

7.4

Development

Successfully merging this pull request may close these issues.

Validator - validateProperty() and validatePropertyValue() give no feedback if the property does not exist

5 participants

@mlussi90@carsonbot@santysisi@nicolas-grekas@m-lussi-c24

[8]ページ先頭

©2009-2025 Movatter.jp