Skip to content

5.x: Entity save error message hidden if domain rules #18241

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

Open
dereuromark opened this issue Mar 19, 2025 · 3 comments
Open

5.x: Entity save error message hidden if domain rules #18241

dereuromark opened this issue Mar 19, 2025 · 3 comments
Milestone

Comments

@dereuromark
Copy link
Member

Description

When doing a save operation with associations, the error message on the assocs can be hidden completely.

            $data['orders'] = ['_ids' => $orderIds];
            $data['deposits'] = ['_ids' => $depositIds];
            $invoice = $this->Invoices->patchEntity($invoice, $data);
            if ($this->Invoices->save($invoice, ['associated' => ['Orders', 'Deposits']])) {

Just returns false, nothing else. Even a saveOrFail() here would only return

Cake\ORM\Exception\PersistenceFailedException: Entity save failure.

After a lot of debugging, setting 'atomic' => false into it revealed the message suddenly:

Cake\ORM\Exception\PersistenceFailedException: Entity save failure. Found the following errors (orders.0._joinData.order_id._isUnique: "This value is already in use").
/vendor/cakephp/cakephp/src/ORM/Table.php:1985

I wonder if there isnt a better way of combining assoc issues into the primary error, so the actual issue is visible for local dev and debugging, but also when logging e.g. on prod.

Right now, with default atomic true those would always be invisible it seems.

CakePHP Version

5.0

PHP Version

8.3

@dereuromark
Copy link
Member Author

dereuromark commented Mar 19, 2025

The data posted is

[
  'event_id' => '1',
  'name' => 'Test Company',
  'street' => 'Test Street 123',
  'zipcode' => '12345',
  'city' => 'Test City',
  'country_id' => '1',
  'email' => 'test@example.com',
  'status' => '1',
  'total_without_tax' => '100',
  'orders' => [
    '_ids' => [
      (int) 0 => '1'
    ]
  ],
  'deposits' => [
    '_ids' => []
  ]
]

The order 1 is existing, so it should only link those via pivot table invoices_orders.

The domain rule fires here:

$rules->add($rules->isUnique(['order_id']), ['errorField' => 'order_id']);

But the issue is the firing of domain rules on assocs are hidden away silently and just returning a bool false.
Super hard to debug.

@dereuromark dereuromark changed the title 5.x: Entity save error message hidden 5.x: Entity save error message hidden if domain rules Mar 19, 2025
@dereuromark dereuromark added this to the 5.1.7 milestone Mar 19, 2025
@markstory
Copy link
Member

Does the $invoice entity get any errors added to it? That could be a reasonable way to get failures like this back out.

I agree that this isn't how the ORM should work and that we should fix this.

@markstory markstory added the ORM label Mar 20, 2025
@dereuromark
Copy link
Member Author

No, nothing in the getErrors() either at the end.

@markstory markstory modified the milestones: 5.1.7, 5.2.1 Mar 29, 2025
@markstory markstory modified the milestones: 5.2.1, 5.2.2 Apr 6, 2025
@markstory markstory modified the milestones: 5.2.2, 5.2.3, 5.2.4 Apr 18, 2025
@markstory markstory modified the milestones: 5.2.4, 5.2.5 May 17, 2025
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

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy