Skip to content
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

PropertyInfoLoader should not try to add validation to non-existent property #31936

Conversation

weaverryan
Copy link
Member

Q A
Branch? 4.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #31796 (see #31796 (comment))
License MIT
Doc PR not needed

With auto-validation, if a class has a setter (e.g. setFoo()) but there is no foo property, it still tries to add validation to that property, resulting in a:

Property "foo" does not exist in class "App\Entity\Bar

This fixes that. I believe it's "just this simple", but I don't have any experience with the code in this area yet.

Cheers!

@@ -60,6 +60,10 @@ public function loadClassMetadata(ClassMetadata $metadata)
continue;
}

if (false === property_exists($className, $property)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

property_exists() is what is used in PropertyMetadata, which triggered the exception. This matches that.

@@ -46,6 +46,7 @@ public function testLoadClassMetadata()
'alreadyMappedNotBlank',
'alreadyPartiallyMappedCollection',
'readOnly',
'nonExistentField',
Copy link
Member Author

Choose a reason for hiding this comment

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

No asserts were added, but, without the fix, these changes are enough to trigger an exception to be thrown while running this test.

@nicolas-grekas nicolas-grekas added this to the 4.3 milestone Jun 7, 2019
@weaverryan weaverryan force-pushed the no-auto-validation-on-non-existent-prop branch from 89f72a1 to b702598 Compare June 7, 2019 18:22
@nicolas-grekas
Copy link
Member

Thank you @weaverryan.

@nicolas-grekas nicolas-grekas merged commit b702598 into symfony:4.3 Jun 7, 2019
nicolas-grekas added a commit that referenced this pull request Jun 7, 2019
…-existent property (weaverryan)

This PR was merged into the 4.3 branch.

Discussion
----------

PropertyInfoLoader should not try to add validation to non-existent property

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31796 (see #31796 (comment))
| License       | MIT
| Doc PR        | not needed

With auto-validation, if a class has a setter (e.g. `setFoo()`) but there is no `foo` property, it still tries to add validation to that property, resulting in a:

> Property "foo" does not exist in class "App\Entity\Bar

This fixes that. I believe it's "just this simple", but I don't have any experience with the code in this area yet.

Cheers!

Commits
-------

b702598 Fixing bug where PropertyInfoLoader tried to add validation to non-existent properties
@weaverryan weaverryan deleted the no-auto-validation-on-non-existent-prop branch June 7, 2019 18:28
@dunglas
Copy link
Member

dunglas commented Jun 8, 2019

Looks good to me! Thank you Ryan.

@fabpot fabpot mentioned this pull request Jun 26, 2019
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.

None yet

6 participants