<p dir="auto">Dear Fabien,<br>
Thank you for uploading your slides on the symphony hack day in Berlin.<br>
I played around with the expression language and the got the error, that in the router the request is missing.</p>
<p dir="auto">I created a fork of symfony standard to reproduce the problem:<br>
<a href="https://github.com/sebastianblum/symfony-standard/tree/routing-condition">https://github.com/sebastianblum/symfony-standard/tree/routing-condition</a></p>
<p dir="auto">If I add the condition in the routing.yml</p>
<p dir="auto">condition: "request.getMethod() in ['GET', 'POST'] and request.headers.get('User-Agent') matches '/firefox/i'"<br>
see <a href="https://github.com/sebastianblum/symfony-standard/blob/routing-condition/src/Acme/DemoBundle/Resources/config/routing.yml">https://github.com/sebastianblum/symfony-standard/blob/routing-condition/src/Acme/DemoBundle/Resources/config/routing.yml</a></p>
<p dir="auto">then I got the following error:</p>
<p dir="auto">FatalErrorException: Error: Call to a member function getMethod() on a non-object<br>
See complete stack trace <a href="https://gist.github.com/sebastianblum/7417064">https://gist.github.com/sebastianblum/7417064</a></p>
<p dir="auto"><strong>Symfony version(s) affected</strong>: 4.2.2</p>
<p dir="auto"><strong>Description</strong><br>
The unique constraint validation does not work when the form collection entry type is mapped with an entity that have an unique constraint.</p>
<p dir="auto"><strong>How to reproduce</strong></p>
<p dir="auto">Parent entity:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/**
 * @ORM\Entity()
 */
class Family
{
    /**
     * Many Families has Many Attributes
     * 
     * @var ArrayCollection
     * 
     * @ORM\OneToMany(targetEntity=&quot;App\Entity\FamilyAttribute&quot;, mappedBy=&quot;family&quot;, orphanRemoval=true, cascade={&quot;persist&quot;})
     * @Assert\Valid()
     */
    private $familyAttributes;
}"><pre class="notranslate"><code class="notranslate">/**
 * @ORM\Entity()
 */
class Family
{
    /**
     * Many Families has Many Attributes
     * 
     * @var ArrayCollection
     * 
     * @ORM\OneToMany(targetEntity="App\Entity\FamilyAttribute", mappedBy="family", orphanRemoval=true, cascade={"persist"})
     * @Assert\Valid()
     */
    private $familyAttributes;
}
</code></pre></div>
<p dir="auto">Child entity:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/**
 * THIS IS A JOIN TABLE WITH ADDITIONAL ATTRIBUTES
 *
 * @ORM\Entity()
 * @ORM\Table(uniqueConstraints={@UniqueConstraint(name=&quot;family_attribute_idx&quot;, columns={&quot;family_id&quot;, &quot;attribute_id&quot;})})
 * @UniqueEntity({&quot;family&quot;, &quot;attribute&quot;}, errorPath=&quot;attribute&quot;);
 */
class FamilyAttribute
{
    /**
     * @var Family
     * 
     * @ORM\ManyToOne(targetEntity=&quot;App\Entity\Family&quot;, inversedBy=&quot;familyAttributes&quot;)
     * @ORM\JoinColumn(nullable=false)
     */
    private $family;

    /**
     * @var Attribute
     * 
     * @ORM\ManyToOne(targetEntity=&quot;App\Entity\Attribute&quot;, inversedBy=&quot;familyAttributes&quot;)
     * @ORM\JoinColumn(nullable=false)
     * @Assert\NotBlank()
     */
    private $attribute;
}"><pre class="notranslate"><code class="notranslate">/**
 * THIS IS A JOIN TABLE WITH ADDITIONAL ATTRIBUTES
 *
 * @ORM\Entity()
 * @ORM\Table(uniqueConstraints={@UniqueConstraint(name="family_attribute_idx", columns={"family_id", "attribute_id"})})
 * @UniqueEntity({"family", "attribute"}, errorPath="attribute");
 */
class FamilyAttribute
{
    /**
     * @var Family
     * 
     * @ORM\ManyToOne(targetEntity="App\Entity\Family", inversedBy="familyAttributes")
     * @ORM\JoinColumn(nullable=false)
     */
    private $family;

    /**
     * @var Attribute
     * 
     * @ORM\ManyToOne(targetEntity="App\Entity\Attribute", inversedBy="familyAttributes")
     * @ORM\JoinColumn(nullable=false)
     * @Assert\NotBlank()
     */
    private $attribute;
}
</code></pre></div>
<p dir="auto">The form type:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        $builder
            -&gt;add('familyAttributes', CollectionType::class, [
                'entry_type' =&gt; FamilyAttributeType::class,
                'allow_add' =&gt; true,
            ])
        ;"><pre class="notranslate"><code class="notranslate">        $builder
            -&gt;add('familyAttributes', CollectionType::class, [
                'entry_type' =&gt; FamilyAttributeType::class,
                'allow_add' =&gt; true,
            ])
        ;
</code></pre></div>
<p dir="auto">The issue occurs when I add two "FamilyAttribute" with the same {$family; $attribute} pair.</p>
<p dir="auto">The UniqueConstraint validation does not work if the duplicate collection entries are not already persisted in the database.</p>
<p dir="auto"><strong>Possible Solution</strong><br>
No idea.</p>