Skip to content

Conversation

@mlussi90
Copy link

@mlussi90 mlussi90 commented Oct 30, 2025

Q A
Branch? 7.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #62198
License MIT

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 issue symfony#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.
@carsonbot carsonbot added this to the 7.4 milestone Oct 30, 2025
@carsonbot carsonbot changed the title Throw ValidatorException when validating non-existent property Throw ValidatorException when validating non-existent property Oct 30, 2025
@carsonbot
Copy link

Hey!

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

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://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 caused
tests 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 should
return 0 violations, while still throwing an exception for properties
that don't exist at all.
@carsonbot carsonbot changed the title Throw ValidatorException when validating non-existent property [Validator] Throw ValidatorException when validating non-existent property Oct 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-grekas nicolas-grekas Oct 31, 2025

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?

@nicolas-grekas nicolas-grekas modified the milestones: 7.4, 8.1 Nov 16, 2025
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.

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

5 participants