8000 bug #31936 PropertyInfoLoader should not try to add validation to non… · symfony/symfony@e718458 · GitHub
[go: up one dir, main page]

Skip to content

Commit e718458

Browse files
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 #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
2 parents 5cec9e7 + b702598 commit e718458

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public function loadClassMetadata(ClassMetadata $metadata)
6060
continue;
6161
}
6262

63+
if (!property_exists($className, $property)) {
64+
continue;
65+
}
66+
6367
$types = $this->typeExtractor->getTypes($className, $property);
6468
if (null === $types) {
6569
continue;

src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ class PropertyInfoLoaderEntity
4848
public $alreadyPartiallyMappedCollection;
4949

5050
public $readOnly;
51+
52+
public function setNonExistentField()
53+
{
54+
}
5155
}

src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function testLoadClassMetadata()
4646
'alreadyMappedNotBlank',
4747
'alreadyPartiallyMappedCollection',
4848
'readOnly',
49+
'nonExistentField',
4950
])
5051
;
5152
$propertyInfoStub

0 commit comments

Comments
 (0)
0