'Attempt to update entity without persisting on it DOCTRINE

I have a Product entity with a ManyToOne relationship with Category.

use Doctrine\ORM\Mapping as ORM;

class Product
{
    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Category")
     * @ORM\JoinColumn(nullable=true)
     */
    private $category;
}
class Category
{
    use BlameableTrait;

    ...
}

The Category entity implements a trait, with properties to record when a record is created, updated, etc.


use App\Entity\User\User;
use Gedmo\Mapping\Annotation as Gedmo;

trait BlameableTrait
{
    /**
     * @Gedmo\Blameable(on="create")
     * @ORM\ManyToOne(targetEntity="App\Entity\User\User")
     * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
     * @var User
     */
    private $createdBy;

    /**
     * @var User|null
     *
     * @Gedmo\Blameable(on="update")
     * @ORM\ManyToOne(targetEntity="App\Entity\User\User")
     * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
     */
    private $updatedBy;

    public function getCreatedBy(): ?User
    {
        return $this->createdBy;
    }

    public function setCreatedBy(?User $createdBy): self
    {
        $this->createdBy = $createdBy;

        return $this;
    }

    public function setUpdatedBy(?User $updatedBy): self
    {
        $this->updatedBy = $updatedBy;

        return $this;
    }

    public function getUpdatedBy(): ?User
    {
        return $this->updatedBy;
    }
}

When I try to update the product entity I have an error indicating that an error has occurred while trying to update the Category entity, but I have not indicated that it should be updated.

This only happens to me in the production environment and randomly, one time it works, another time it doesn't. Locally, debugging the symfony profiler, for the same curl, only one update is done on the Product entity, which is fine.

I don't understand where Symfony or Doctrine try to update the Category entity.

Both the production and local environments run on the same Docker image.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source