-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyInfo] [Validator] the new auto mapping is not working with non found property #31796
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
Comments
Today I updated Symfony 4.2 to 4.3 and now I can't save entities that implement Interfaces or use traits, Mapping/PropertyMetadata class try to find a property in a interface and throw an error, my code snippet: interface GetterIdInterface
{
public function getId();
} class MyEntity implements GetterIdInterface
{
/**
* @var string
*
* @ORM\Column(name="id", type="guid", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="UUID")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255, nullable=false)
* @Assert\NotBlank()
*/
protected $title;
public function getId()
{
return $this->id;
}
/**
* Set title.
*
* @param string $title
*
* @return MyEntity
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title.
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
} //When I try to save MyEntity throw an exception:
...
$entity = new MyEntity();
$em->persist($entity);
$em->flush();
...
any idea? |
Is this issue related to #31715? |
I don't know if it's exactly the same, because I can save all my entities if they not implement an Interface o use Traits... |
I copy and paste here for clarity and more context, my (closed) issue (#31873): Symfony version(s) affected: 4.3.0 Description
Obviously it doesn't exist as the property is actually So I have a method The problem is caused by the validation framework:
validation:
email_validation_mode: html5
# Enables validator auto-mapping support.
# For instance, basic validation constraints will be inferred from Doctrine's metadata.
#auto_mapping:
# App\Entity\: []
The |
I can confirm this, here is a simple reproducer: https://github.com/weaverryan/symfony-automapper-reproducer - you can see the simple steps in the history:
|
…-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
Perfect, now works! |
Symfony version(s) affected: 4.3.0
Description
When we are using a function like
public function addSomething()
and no property with name:something
not existing the exception "The entity has no field with name ..." is thrown.How to reproduce
Create an entity with function
addSomething()
without propertysomething
and enable the auto mapping for validation.Possible Solution
Additional context
The text was updated successfully, but these errors were encountered: