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

[DoctrineBridge] DoctrineLoader can't access embedded object properties #31775

Closed
Korbeil opened this issue May 31, 2019 · 7 comments
Closed

Comments

@Korbeil
Copy link
Contributor

Korbeil commented May 31, 2019

Symfony version(s) affected: 4.3.0

Description
I just upgraded my application to 4.3.0 and saw this bug.
We have a UserAddress entity:

/**
 * @ORM\Table(name="user_address")
 */
class UserAddress
{
    /**
     * @var Address
     *
     * @ORM\Embedded(class="Address")
     */
    private $address;

    // ...
}

with an embedded object Address:

/**
 * @ORM\Embeddable
 */
class Address
{
    /**
     * @var null|string
     *
     * @ORM\Column(name="first_name", type="string", length=255, nullable=true)
     */
    private $firstName;

    // ...
}

With new Doctrine auto-validation feature, it tries to access address.firstName property, but in https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Validator/Mapping/PropertyMetadata.php#L39, we check if given property exists as it's given, so it can't work.

Possible Solution
Use symfony/property-accessor ? Instead of reflection metadata which does not contains embedded objects metadata.

@MinusSevenOfSpades
Copy link

MinusSevenOfSpades commented May 31, 2019

Same problem here.

My entity Tag have this property:

/**
* @ORM\Embedded(class="App\Doctrine\Embeddable\TagAdditional")
*
* @var TagAdditional|null
*/
protected $additional;

First property in embeddable generates Symfony\Component\Validator\Exception\ValidatorException exception with message Property "additional.headerText" does not exist in class "App\Entity\Tag".

/**
* @ORM\Column(name="header_text", type="string", length=255, nullable=true)
*
* @Assert\Length(max="250")
*
* @var string|null
*/
protected $headerText;

Updated to Symfony 4.3 hour ago.
Problem can be temporarly fixed if we use doctrine/common:v2.8.1 instead of latest version.

@dunglas
Copy link
Member

dunglas commented Jun 1, 2019

Shouldn’t it be fixed in the Doctrine loader directly? Simply skipping Embedebbables in the parent class should be enough, and won’t prevent auto-validation to work because metadata are still stored in the child class (to be verified).

I don’t have a computer this weekend, but I’ll try to work on a fix on Monday.

@xabbuh
Copy link
Member

xabbuh commented Jun 3, 2019

I found the root cause. Working on a fix.

@xabbuh
Copy link
Member

xabbuh commented Jun 3, 2019

see #31811

@fabpot fabpot closed this as completed Jun 4, 2019
fabpot added a commit that referenced this issue Jun 4, 2019
… class metadata (xabbuh)

This PR was merged into the 4.3 branch.

Discussion
----------

[DoctrineBridge] don't add embedded properties to wrapping class metadata

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31775
| License       | MIT
| Doc PR        |

Commits
-------

56fe025 don't add embedded properties to wrapping class metadata
@martiis
Copy link
Contributor

martiis commented Jun 6, 2019

With nested embedded objects it's still the same problem.
f.e. embedded object in embedded object in entity.

@xabbuh
Copy link
Member

xabbuh commented Jun 6, 2019

@martiis Can you open a new issue and provide a small example application that allows to reproduce?

@martiis
Copy link
Contributor

martiis commented Jun 6, 2019

sure, but in about 1-2 hours, commuting :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants