bug #31936 PropertyInfoLoader should not try to add validation to non-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 https://github.com/symfony/symfony/issues/31796#issuecomment-499924238)
| 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
-------
b702598b0b
Fixing bug where PropertyInfoLoader tried to add validation to non-existent properties
This commit is contained in:
commit
e7184588e7
@ -60,6 +60,10 @@ final class PropertyInfoLoader implements LoaderInterface
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!property_exists($className, $property)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$types = $this->typeExtractor->getTypes($className, $property);
|
$types = $this->typeExtractor->getTypes($className, $property);
|
||||||
if (null === $types) {
|
if (null === $types) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -48,4 +48,8 @@ class PropertyInfoLoaderEntity
|
|||||||
public $alreadyPartiallyMappedCollection;
|
public $alreadyPartiallyMappedCollection;
|
||||||
|
|
||||||
public $readOnly;
|
public $readOnly;
|
||||||
|
|
||||||
|
public function setNonExistentField()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ class PropertyInfoLoaderTest extends TestCase
|
|||||||
'alreadyMappedNotBlank',
|
'alreadyMappedNotBlank',
|
||||||
'alreadyPartiallyMappedCollection',
|
'alreadyPartiallyMappedCollection',
|
||||||
'readOnly',
|
'readOnly',
|
||||||
|
'nonExistentField',
|
||||||
])
|
])
|
||||||
;
|
;
|
||||||
$propertyInfoStub
|
$propertyInfoStub
|
||||||
|
Reference in New Issue
Block a user