Problem/Motivation

Drupal\Core\Entity\EntityStorageException: 'mailer_policy' entity with ID '_' already exists. in Drupal\Core\Entity\EntityStorageBase->doPreSave() (line 557 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).

Steps to reproduce

  • Go to /admin/config/system/mailer/policy/add
  • Select Type *All* and click "Add and configure"

Proposed resolution

In PolicyAddForm::validateForm() there is a @todo marker that would solve this issue. Add a check if the policy already exists, and if so fail validation with an error message. The message should include a link to edit the already existing entity.

Comments

guedressel created an issue. See original summary.

adamps’s picture

Title: Exception: Add Policy of Type "*All*" » Exception: Add Policy that already exists

Thanks for the report. I think it will be the same bug when adding any policy that already exists

larisse’s picture

StatusFileSize
new558 bytes

Hi! I was debugging this issue, so I noticed that this error is because the id is seted by '_'.
I have a simple solution to solve this, but I'm not sure if this the better solution, that was generate random values for the id...
If this solution is good, let me know... Because the work now will be just find a way to check if the exist an entity with the id random generated to complete the patch...

larisse’s picture

Status: Active » Needs review
guedressel’s picture

This very config entity (was) defined in https://git.drupalcode.org/project/symfony_mailer/-/blob/1.0.0-alpha4/mo...
It seems to be gone on the 1.x branch now.

adamps’s picture

Issue summary: View changes
Status: Needs review » Active

I added a proposed resolution to the IS.

The _ policy is still there, just it moved to https://git.drupalcode.org/project/symfony_mailer/-/blob/1.x/config/inst...

Egor Grigoriev’s picture

Version: 1.0.0-alpha4 » 1.0.0-alpha10
Status: Active » Needs review
StatusFileSize
new2.08 KB

Hey guys, I want to offer my solution. If I understand correctly, we can only have one policy for one type. I decide to complete form validation for this purpose.

adamps’s picture

Thanks for the patch, that's exactly the right idea.

I tidied up, here is a new version. Please can someone check?

boychev’s picture

Many thanks for your solution, Egor Grigoriev, AdamPS. Works to me perfectly.

adamps’s picture

Status: Needs review » Fixed

Thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.