EasyCorp / EasyCorp/EasyAdminBundle

Bug after PR 7600

Open
#7,721 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
4.3k
Forks
1.1k
Avg merge
8d 2h
Merged PRs (30d)
11

Description

Hello
Related #7600

Describe the bug
After #7600 on my project I got a bug - createEntity called unexpectly while editing entries.

To Reproduce

class CrossSell
{
__construct(
        #[ORM\ManyToOne(targetEntity: CrossSellCampaign::class, inversedBy: 'crossSells')]
        #[ORM\JoinColumn(name: 'campaign_id', nullable: false)]
        private CrossSellCampaign $campaign,
)
{
$this->campaign->addCrossSell($this); // this needed to  consistent two-way relations (Symfony way)
}
}
class CrossSellCrudController extends AbstractCrudController
{
    public function createEntity(string $entityFqcn): CrossSell
    {
        $campaign = $this->em->getRepository(CrossSellCampaign::class)->findOneBy([]);
        assert($campaign instanceof CrossSellCampaign);
        $po = $this->em->getRepository(PriceOption::class)->findOneBy([]);
        assert($po instanceof PriceOption);

        $entity = new CrossSell(
            $campaign,
            $po,
            position: 0,
            placement: PlacementEnum::PROMO_BLOCK,
            actionType: ActionTypeEnum::ADD,
        );

        return $entity;
    }
}

After edit form opened a new random element is added to Campaign since createEntity is called unexpectedly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at createEntity in the provided CrossSellCrudController example and inspect the behavior introduced by PR #7600. Reproduce the issue with the provided CrossSell entity and edit form; done means opening an edit form no longer adds a new Campaign element or calls createEntity unexpectedly.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.